tokio-rs / valuable

MIT License
185 stars 19 forks source link

implement valuable for Path #113

Open eliad-wiz opened 1 year ago

eliad-wiz commented 1 year ago

implement valuable for Path instead of &Path, in order to support types like Box

taiki-e commented 1 year ago

Thanks for the PR. IIRC, I implemented Valuable for the reference to match the Valuable implementation of str.

eliad-wiz commented 1 year ago

the &str impl uses some specific optimization for slices:

impl Valuable for &'_ str {
    fn as_value(&self) -> Value<'_> {
        Value::String(self)
    }

    fn visit(&self, visit: &mut dyn Visit) {
        visit.visit_value(Value::String(self));
    }

    fn visit_slice(slice: &[Self], visit: &mut dyn Visit)
    where
        Self: Sized,
    {
        visit.visit_primitive_slice(Slice::Str(slice));
    }
}

Path is not a primitive type, so i guess it's different. (btw, currently the implementation for Box in indeed missing. i guess it should either be added explicitly or the &str impl should be changed to str as well)