why some_table.get_mut("xxx")
returns Some(None)
#777
Replies: 2 comments
-
this will solve if dependencies.get("some_dep").is_none() {
let mut dep_table= toml_edit::table();
dep_table["version"] = toml_edit::value("some_version");
dep_table["features"] = toml_edit::value(dep_feature);
dependencies["some_dep"] = dep_table;
} else {
dependencies["some_dep"]["features"] = toml_edit::value(dep_feature);
} but I just wonder why |
Beta Was this translation helpful? Give feedback.
0 replies
-
ok, I found this: fn index_mut<'v>(&self, v: &'v mut Item) -> Option<&'v mut Item> {
if let Item::None = *v {
let mut t = InlineTable::default();
t.items.insert(
InternalString::from(self),
TableKeyValue::new(Key::new(self), Item::None),
);
*v = value(Value::InlineTable(t));
}
match *v {
Item::Table(ref mut t) => Some(t.entry(self).or_insert(Item::None)),
Item::Value(ref mut v) => v.as_inline_table_mut().map(|t| {
&mut t
.items
.entry(InternalString::from(self))
.or_insert_with(|| TableKeyValue::new(Key::new(self), Item::None))
.value
}),
_ => None,
}
} I think it's because |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
as my title
If the dependency already exist, then I'll just modify the features, otherwise I'll add this dependency it's features
then i found it always run the first branch because
dependencies.get_mut("some_dep")
returnsSome(None)
when the dependency is not existIs there a better way to do it?
Beta Was this translation helpful? Give feedback.
All reactions