-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to allow to visit a value referencing data owned by the current function? #43
Comments
Another case of this problem is when I want to pass struct PathAsStr(std::path::PathBuf);
impl Valuable for PathAsStr {
fn as_value(&self) -> Value<'_> {
#[derive(Debug)]
struct Error;
static ERROR: Error = Error;
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&"path is not valid UTF-8 string", f)
}
}
impl std::error::Error for Error {}
match self.0.to_str() {
Some(s) => Value::String(s),
None => Value::Error(&ERROR),
}
}
fn visit(&self, visit: &mut dyn Visit) {
visit.visit_value(self.as_value());
}
} |
Well, the intent is that we avoid work in the Value::Display(&dyn Display) In the second case, the error is then received when visiting and the visitor can handle it as it wishes. |
Ref: #4 We also may want to add a |
Hmm. The creation of That said, I think that |
When I ran into this case in the past I ended up with an API like this: https://docs.rs/value-bag/1.0.0-alpha.7/value_bag/fill/index.html The variant on |
When working with valuable in handlebars, I may have a case for this issue as well. During a template rendering process, some intermediate values are computed and are owned by internal context. If I will use Not quite sure if this matches original rational of valuable. But it seems to be required to use in handlebars. |
triage: A variant of Value to handle this (Value::Displayable?) can be added later without API break, so there is no need to consider this as a blocker of 0.1.0. |
AFAIK, in the current API,
Valuable
cannot be implemented well if I need a temporarily owned value for serialization.Is there a way to handle such cases well?
(I was thinking a bit about removing the
Valuable::as_value
, but not sure if that would be a good idea.)The text was updated successfully, but these errors were encountered: