pub fn to_toml(&self, crate_root: &Path) -> toml_edit::Item {
        assert!(
            crate_root.is_absolute(),
            "Absolute path needed, got: {}",
            crate_root.display()
        );
        let table: toml_edit::Item = match (
            self.optional.unwrap_or(false),
            self.features.as_ref(),
            self.default_features.unwrap_or(true),
            self.source.as_ref(),
            self.registry.as_ref(),
            self.rename.as_ref(),
        ) {
            // Extra short when version flag only
            (
                false,
                None,
                true,
                Some(Source::Registry(RegistrySource { version: v })),
                None,
                None,
            ) => toml_edit::value(v),
            (false, None, true, Some(Source::Workspace(WorkspaceSource {})), None, None) => {
                let mut table = toml_edit::InlineTable::default();
                table.set_dotted(true);
                table.insert("workspace", true.into());
                toml_edit::value(toml_edit::Value::InlineTable(table))
            }
            // Other cases are represented as an inline table
            (_, _, _, _, _, _) => {
                let mut table = toml_edit::InlineTable::default();

                match &self.source {
                    Some(Source::Registry(src)) => {
                        table.insert("version", src.version.as_str().into());
                    }
                    Some(Source::Path(src)) => {
                        let relpath = path_field(crate_root, &src.path);
                        if let Some(r) = src.version.as_deref() {
                            table.insert("version", r.into());
                        }
                        table.insert("path", relpath.into());
                    }
                    Some(Source::Git(src)) => {
                        table.insert("git", src.git.as_str().into());
                        if let Some(branch) = src.branch.as_deref() {
                            table.insert("branch", branch.into());
                        }
                        if let Some(tag) = src.tag.as_deref() {
                            table.insert("tag", tag.into());
                        }
                        if let Some(rev) = src.rev.as_deref() {
                            table.insert("rev", rev.into());
                        }
                        if let Some(r) = src.version.as_deref() {
                            table.insert("version", r.into());
                        }
                    }
                    Some(Source::Workspace(_)) => {
                        table.insert("workspace", true.into());
                    }
                    None => {}
                }
                if table.contains_key("version") {
                    if let Some(r) = self.registry.as_deref() {
                        table.insert("registry", r.into());
                    }
                }

                if self.rename.is_some() {
                    table.insert("package", self.name.as_str().into());
                }
                if let Some(v) = self.default_features {
                    table.insert("default-features", v.into());
                }
                if let Some(features) = self.features.as_ref() {
                    let features: toml_edit::Value = features.iter().cloned().collect();
                    table.insert("features", features);
                }
                if let Some(v) = self.optional {
                    table.insert("optional", v.into());
                }

                toml_edit::value(toml_edit::Value::InlineTable(table))
            }
        };

        table
    }
/// Convert dependency to TOML
///
/// Returns a tuple with the dependency's name and either the version as a `String`
/// or the path/git repository as an `InlineTable`.
/// (If the dependency is set as `optional` or `default-features` is set to `false`,
/// an `InlineTable` is returned in any case.)
///
/// # Panic
///
/// Panics if the path is relative
Convert dependency to TOML
Returns a tuple with the dependency's name and either the version as a `String`
or the path/git repository as an `InlineTable`.
Convert dependency to TOML Returns a tuple with the dependency ' s name and either the version as a ` String ` or the path / git repository as an ` InlineTable ` .
pub fn to_toml(&self, crate_root: &Path) -> toml_edit::Item {
        assert!(
            crate_root.is_absolute(),
            "Absolute path needed, got: {}",
            crate_root.display()
        );
        let table: toml_edit::Item = match (
            self.optional.unwrap_or(false),
            self.features.as_ref(),
            self.default_features.unwrap_or(true),
            self.source.as_ref(),
            self.registry.as_ref(),
            self.rename.as_ref(),
        ) {
            // Extra short when version flag only
            (
                false,
                None,
                true,
                Some(Source::Registry(RegistrySource { version: v })),
                None,
                None,
            ) => toml_edit::value(v),
            (false, None, true, Some(Source::Workspace(WorkspaceSource {})), None, None) => {
                let mut table = toml_edit::InlineTable::default();
                table.set_dotted(true);
                table.insert("workspace", true.into());
                toml_edit::value(toml_edit::Value::InlineTable(table))
            }
            // Other cases are represented as an inline table
            (_, _, _, _, _, _) => {
                let mut table = toml_edit::InlineTable::default();
                match &self.source {
                    Some(Source::Registry(src)) => {
                        table.insert("version", src.version.as_str().into());
                    }
                    Some(Source::Path(src)) => {
                        let relpath = path_field(crate_root, &src.path);
                        if let Some(r) = src.version.as_deref() {
                            table.insert("version", r.into());
                        }
                        table.insert("path", relpath.into());
                    }
                    Some(Source::Git(src)) => {
                        table.insert("git", src.git.as_str().into());
                        if let Some(branch) = src.branch.as_deref() {
                            table.insert("branch", branch.into());
                        }
                        if let Some(tag) = src.tag.as_deref() {
                            table.insert("tag", tag.into());
                        }
                        if let Some(rev) = src.rev.as_deref() {
                            table.insert("rev", rev.into());
                        }
                        if let Some(r) = src.version.as_deref() {
                            table.insert("version", r.into());
                        }
                    }
                    Some(Source::Workspace(_)) => {
                        table.insert("workspace", true.into());
                    }
                    None => {}
                }
                if table.contains_key("version") {
                    if let Some(r) = self.registry.as_deref() {
                        table.insert("registry", r.into());
                    }
                }
                if self.rename.is_some() {
                    table.insert("package", self.name.as_str().into());
                }
                if let Some(v) = self.default_features {
                    table.insert("default-features", v.into());
                }
                if let Some(features) = self.features.as_ref() {
                    let features: toml_edit::Value = features.iter().cloned().collect();
                    table.insert("features", features);
                }
                if let Some(v) = self.optional {
                    table.insert("optional", v.into());
                }
                toml_edit::value(toml_edit::Value::InlineTable(table))
            }
        };
        table
    }
pub fn to_toml ( & self , crate_root : & Path ) -> toml_edit :: Item { assert ! ( crate_root is_absolute ( ) " " crate_root display ( ) ) ; let table : toml_edit :: Item = match ( self . optional . unwrap_or ( false ) , self . features . as_ref ( ) , self . default_features . unwrap_or ( true ) , self . source . as_ref ( ) , self . registry . as_ref ( ) , self . rename . as_ref ( ) , ) { // Extra short when version flag only ( false , None , true , Some ( Source :: Registry ( RegistrySource { version : v } ) ) , None , None , ) => toml_edit :: value ( v ) , ( false , None , true , Some ( Source :: Workspace ( WorkspaceSource { } ) ) , None , None ) => { let mut table = toml_edit :: InlineTable :: default ( ) ; table . set_dotted ( true ) ; table . insert ( " " , true . into ( ) ) ; toml_edit :: value ( toml_edit :: Value :: InlineTable ( table ) ) } // Other cases are represented as an inline table ( _ , _ , _ , _ , _ , _ ) => { let mut table = toml_edit :: InlineTable :: default ( ) ; match & self . source { Some ( Source :: Registry ( src ) ) => { table . insert ( " " , src . version . as_str ( ) . into ( ) ) ; } Some ( Source :: Path ( src ) ) => { let relpath = path_field ( crate_root , & src . path ) ; if let Some ( r ) = src . version . as_deref ( ) { table . insert ( " " , r . into ( ) ) ; } table . insert ( " " , relpath . into ( ) ) ; } Some ( Source :: Git ( src ) ) => { table . insert ( " " , src . git . as_str ( ) . into ( ) ) ; if let Some ( branch ) = src . branch . as_deref ( ) { table . insert ( " " , branch . into ( ) ) ; } if let Some ( tag ) = src . tag . as_deref ( ) { table . insert ( " " , tag . into ( ) ) ; } if let Some ( rev ) = src . rev . as_deref ( ) { table . insert ( " " , rev . into ( ) ) ; } if let Some ( r ) = src . version . as_deref ( ) { table . insert ( " " , r . into ( ) ) ; } } Some ( Source :: Workspace ( _ ) ) => { table . insert ( " " , true . into ( ) ) ; } None => { } } if table . contains_key ( " " ) { if let Some ( r ) = self . registry . as_deref ( ) { table . insert ( " " , r . into ( ) ) ; } } if self . rename . is_some ( ) { table . insert ( " " , self . name . as_str ( ) . into ( ) ) ; } if let Some ( v ) = self . default_features { table . insert ( " " , v . into ( ) ) ; } if let Some ( features ) = self . features . as_ref ( ) { let features : toml_edit :: Value = features . iter ( ) . cloned ( ) . collect ( ) ; table . insert ( " " , features ) ; } if let Some ( v ) = self . optional { table . insert ( " " , v . into ( ) ) ; } toml_edit :: value ( toml_edit :: Value :: InlineTable ( table ) ) } } ; table }
Convert dependency to TOML
Returns a tuple with the dependency's name and either the version as a `String`
or the path/git repository as an `InlineTable`.
Convert dependency to TOML Returns a tuple with the dependency ' s name and either the version as a ` String ` or the path / git repository as an ` InlineTable ` .
&self
crate_root
&Path
&self
crate_root
&Path
panic
Panics if the path is relative
Panics if the path is relative