pub fn update_toml<'k>(
        &self,
        crate_root: &Path,
        key: &mut KeyMut<'k>,
        item: &mut toml_edit::Item,
    ) {
        if str_or_1_len_table(item) {
            // Nothing to preserve
            *item = self.to_toml(crate_root);
            key.fmt();
        } else if let Some(table) = item.as_table_like_mut() {
            match &self.source {
                Some(Source::Registry(src)) => {
                    table.insert("version", toml_edit::value(src.version.as_str()));

                    for key in ["path", "git", "branch", "tag", "rev", "workspace"] {
                        table.remove(key);
                    }
                }
                Some(Source::Path(src)) => {
                    let relpath = path_field(crate_root, &src.path);
                    table.insert("path", toml_edit::value(relpath));
                    if let Some(r) = src.version.as_deref() {
                        table.insert("version", toml_edit::value(r));
                    } else {
                        table.remove("version");
                    }

                    for key in ["git", "branch", "tag", "rev", "workspace"] {
                        table.remove(key);
                    }
                }
                Some(Source::Git(src)) => {
                    table.insert("git", toml_edit::value(src.git.as_str()));
                    if let Some(branch) = src.branch.as_deref() {
                        table.insert("branch", toml_edit::value(branch));
                    } else {
                        table.remove("branch");
                    }
                    if let Some(tag) = src.tag.as_deref() {
                        table.insert("tag", toml_edit::value(tag));
                    } else {
                        table.remove("tag");
                    }
                    if let Some(rev) = src.rev.as_deref() {
                        table.insert("rev", toml_edit::value(rev));
                    } else {
                        table.remove("rev");
                    }
                    if let Some(r) = src.version.as_deref() {
                        table.insert("version", toml_edit::value(r));
                    } else {
                        table.remove("version");
                    }

                    for key in ["path", "workspace"] {
                        table.remove(key);
                    }
                }
                Some(Source::Workspace(_)) => {
                    table.insert("workspace", toml_edit::value(true));
                    table.set_dotted(true);
                    key.fmt();
                    for key in [
                        "version",
                        "registry",
                        "registry-index",
                        "path",
                        "git",
                        "branch",
                        "tag",
                        "rev",
                        "package",
                        "default-features",
                    ] {
                        table.remove(key);
                    }
                }
                None => {}
            }
            if table.contains_key("version") {
                if let Some(r) = self.registry.as_deref() {
                    table.insert("registry", toml_edit::value(r));
                } else {
                    table.remove("registry");
                }
            } else {
                table.remove("registry");
            }

            if self.rename.is_some() {
                table.insert("package", toml_edit::value(self.name.as_str()));
            }
            match self.default_features {
                Some(v) => {
                    table.insert("default-features", toml_edit::value(v));
                }
                None => {
                    table.remove("default-features");
                }
            }
            if let Some(new_features) = self.features.as_ref() {
                let mut features = table
                    .get("features")
                    .and_then(|i| i.as_value())
                    .and_then(|v| v.as_array())
                    .and_then(|a| {
                        a.iter()
                            .map(|v| v.as_str())
                            .collect::<Option<IndexSet<_>>>()
                    })
                    .unwrap_or_default();
                features.extend(new_features.iter().map(|s| s.as_str()));
                let features = toml_edit::value(features.into_iter().collect::<toml_edit::Value>());
                table.set_dotted(false);
                table.insert("features", features);
            } else {
                table.remove("features");
            }
            match self.optional {
                Some(v) => {
                    table.set_dotted(false);
                    table.insert("optional", toml_edit::value(v));
                }
                None => {
                    table.remove("optional");
                }
            }

            table.fmt();
        } else {
            unreachable!("Invalid dependency type: {}", item.type_name());
        }
    }
/// Modify existing entry to match this dependency
Modify existing entry to match this dependency
Modify existing entry to match this dependency
pub fn update_toml<'k>(
        &self,
        crate_root: &Path,
        key: &mut KeyMut<'k>,
        item: &mut toml_edit::Item,
    ) {
        if str_or_1_len_table(item) {
            // Nothing to preserve
            *item = self.to_toml(crate_root);
            key.fmt();
        } else if let Some(table) = item.as_table_like_mut() {
            match &self.source {
                Some(Source::Registry(src)) => {
                    table.insert("version", toml_edit::value(src.version.as_str()));
                    for key in ["path", "git", "branch", "tag", "rev", "workspace"] {
                        table.remove(key);
                    }
                }
                Some(Source::Path(src)) => {
                    let relpath = path_field(crate_root, &src.path);
                    table.insert("path", toml_edit::value(relpath));
                    if let Some(r) = src.version.as_deref() {
                        table.insert("version", toml_edit::value(r));
                    } else {
                        table.remove("version");
                    }
                    for key in ["git", "branch", "tag", "rev", "workspace"] {
                        table.remove(key);
                    }
                }
                Some(Source::Git(src)) => {
                    table.insert("git", toml_edit::value(src.git.as_str()));
                    if let Some(branch) = src.branch.as_deref() {
                        table.insert("branch", toml_edit::value(branch));
                    } else {
                        table.remove("branch");
                    }
                    if let Some(tag) = src.tag.as_deref() {
                        table.insert("tag", toml_edit::value(tag));
                    } else {
                        table.remove("tag");
                    }
                    if let Some(rev) = src.rev.as_deref() {
                        table.insert("rev", toml_edit::value(rev));
                    } else {
                        table.remove("rev");
                    }
                    if let Some(r) = src.version.as_deref() {
                        table.insert("version", toml_edit::value(r));
                    } else {
                        table.remove("version");
                    }
                    for key in ["path", "workspace"] {
                        table.remove(key);
                    }
                }
                Some(Source::Workspace(_)) => {
                    table.insert("workspace", toml_edit::value(true));
                    table.set_dotted(true);
                    key.fmt();
                    for key in [
                        "version",
                        "registry",
                        "registry-index",
                        "path",
                        "git",
                        "branch",
                        "tag",
                        "rev",
                        "package",
                        "default-features",
                    ] {
                        table.remove(key);
                    }
                }
                None => {}
            }
            if table.contains_key("version") {
                if let Some(r) = self.registry.as_deref() {
                    table.insert("registry", toml_edit::value(r));
                } else {
                    table.remove("registry");
                }
            } else {
                table.remove("registry");
            }
            if self.rename.is_some() {
                table.insert("package", toml_edit::value(self.name.as_str()));
            }
            match self.default_features {
                Some(v) => {
                    table.insert("default-features", toml_edit::value(v));
                }
                None => {
                    table.remove("default-features");
                }
            }
            if let Some(new_features) = self.features.as_ref() {
                let mut features = table
                    .get("features")
                    .and_then(|i| i.as_value())
                    .and_then(|v| v.as_array())
                    .and_then(|a| {
                        a.iter()
                            .map(|v| v.as_str())
                            .collect::<Option<IndexSet<_>>>()
                    })
                    .unwrap_or_default();
                features.extend(new_features.iter().map(|s| s.as_str()));
                let features = toml_edit::value(features.into_iter().collect::<toml_edit::Value>());
                table.set_dotted(false);
                table.insert("features", features);
            } else {
                table.remove("features");
            }
            match self.optional {
                Some(v) => {
                    table.set_dotted(false);
                    table.insert("optional", toml_edit::value(v));
                }
                None => {
                    table.remove("optional");
                }
            }
            table.fmt();
        } else {
            unreachable!("Invalid dependency type: {}", item.type_name());
        }
    }
pub fn update_toml < ' k > ( & self , crate_root : & Path , key : & mut KeyMut < ' k > , item : & mut toml_edit :: Item , ) { if str_or_1_len_table ( item ) { // Nothing to preserve * item = self . to_toml ( crate_root ) ; key . fmt ( ) ; } else if let Some ( table ) = item . as_table_like_mut ( ) { match & self . source { Some ( Source :: Registry ( src ) ) => { table . insert ( " " , toml_edit :: value ( src . version . as_str ( ) ) ) ; for key in [ " " , " " , " " , " " , " " , " " ] { table . remove ( key ) ; } } Some ( Source :: Path ( src ) ) => { let relpath = path_field ( crate_root , & src . path ) ; table . insert ( " " , toml_edit :: value ( relpath ) ) ; if let Some ( r ) = src . version . as_deref ( ) { table . insert ( " " , toml_edit :: value ( r ) ) ; } else { table . remove ( " " ) ; } for key in [ " " , " " , " " , " " , " " ] { table . remove ( key ) ; } } Some ( Source :: Git ( src ) ) => { table . insert ( " " , toml_edit :: value ( src . git . as_str ( ) ) ) ; if let Some ( branch ) = src . branch . as_deref ( ) { table . insert ( " " , toml_edit :: value ( branch ) ) ; } else { table . remove ( " " ) ; } if let Some ( tag ) = src . tag . as_deref ( ) { table . insert ( " " , toml_edit :: value ( tag ) ) ; } else { table . remove ( " " ) ; } if let Some ( rev ) = src . rev . as_deref ( ) { table . insert ( " " , toml_edit :: value ( rev ) ) ; } else { table . remove ( " " ) ; } if let Some ( r ) = src . version . as_deref ( ) { table . insert ( " " , toml_edit :: value ( r ) ) ; } else { table . remove ( " " ) ; } for key in [ " " , " " ] { table . remove ( key ) ; } } Some ( Source :: Workspace ( _ ) ) => { table . insert ( " " , toml_edit :: value ( true ) ) ; table . set_dotted ( true ) ; key . fmt ( ) ; for key in [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] { table . remove ( key ) ; } } None => { } } if table . contains_key ( " " ) { if let Some ( r ) = self . registry . as_deref ( ) { table . insert ( " " , toml_edit :: value ( r ) ) ; } else { table . remove ( " " ) ; } } else { table . remove ( " " ) ; } if self . rename . is_some ( ) { table . insert ( " " , toml_edit :: value ( self . name . as_str ( ) ) ) ; } match self . default_features { Some ( v ) => { table . insert ( " " , toml_edit :: value ( v ) ) ; } None => { table . remove ( " " ) ; } } if let Some ( new_features ) = self . features . as_ref ( ) { let mut features = table . get ( " " ) . and_then ( | i | i . as_value ( ) ) . and_then ( | v | v . as_array ( ) ) . and_then ( | a | { a . iter ( ) . map ( | v | v . as_str ( ) ) . collect :: < Option < IndexSet < _ > > > ( ) } ) . unwrap_or_default ( ) ; features . extend ( new_features . iter ( ) . map ( | s | s . as_str ( ) ) ) ; let features = toml_edit :: value ( features . into_iter ( ) . collect :: < toml_edit :: Value > ( ) ) ; table . set_dotted ( false ) ; table . insert ( " " , features ) ; } else { table . remove ( " " ) ; } match self . optional { Some ( v ) => { table . set_dotted ( false ) ; table . insert ( " " , toml_edit :: value ( v ) ) ; } None => { table . remove ( " " ) ; } } table . fmt ( ) ; } else { unreachable ! ( " " item type_name ( ) ) ; } }
Modify existing entry to match this dependency
Modify existing entry to match this dependency
&self
crate_root
&Path
key
&mut KeyMut<'k>
item
&mut toml_edit::Item
&self
crate_root
&Path
key
&mut KeyMut<'k>
item
&mut toml_edit::Item