Skip to content

implement valuable for Path - #113

Open
eliad-wiz wants to merge 1 commit into
tokio-rs:masterfrom
eliad-wiz:fix_path_impl
Open

implement valuable for Path#113
eliad-wiz wants to merge 1 commit into
tokio-rs:masterfrom
eliad-wiz:fix_path_impl

Conversation

@eliad-wiz

Copy link
Copy Markdown

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

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

Signed-off-by: Eliad Peller <eliad.peller@wiz.io>
@taiki-e

taiki-e commented Apr 4, 2023

Copy link
Copy Markdown
Member

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

@eliad-wiz

Copy link
Copy Markdown
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants