@@ -4,7 +4,7 @@ use std::collections::{BTreeMap, BTreeSet, HashSet};
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use std:: rc:: Rc ;
6
6
7
- use anyhow:: { bail, Context as _} ;
7
+ use anyhow:: { anyhow , bail, Context as _} ;
8
8
use glob:: glob;
9
9
use itertools:: Itertools ;
10
10
use log:: debug;
@@ -1712,63 +1712,132 @@ impl InheritableFields {
1712
1712
}
1713
1713
}
1714
1714
1715
- pub fn dependencies ( & self ) -> Option < BTreeMap < String , TomlDependency > > {
1716
- self . dependencies . clone ( )
1715
+ pub fn dependencies ( & self ) -> CargoResult < BTreeMap < String , TomlDependency > > {
1716
+ self . dependencies . clone ( ) . map_or (
1717
+ Err ( anyhow ! ( "[workspace.dependencies] was not defined" ) ) ,
1718
+ |d| Ok ( d) ,
1719
+ )
1717
1720
}
1718
1721
1719
- pub fn version ( & self ) -> Option < semver:: Version > {
1720
- self . version . clone ( )
1722
+ pub fn get_dependency ( & self , name : & str ) -> CargoResult < TomlDependency > {
1723
+ self . dependencies . clone ( ) . map_or (
1724
+ Err ( anyhow ! ( "[workspace.dependencies] was not defined" ) ) ,
1725
+ |deps| {
1726
+ deps. get ( name) . map_or (
1727
+ Err ( anyhow ! (
1728
+ "dependency {} was not found in [workspace.dependencies]" ,
1729
+ name
1730
+ ) ) ,
1731
+ |dep| Ok ( dep. clone ( ) ) ,
1732
+ )
1733
+ } ,
1734
+ )
1721
1735
}
1722
1736
1723
- pub fn authors ( & self ) -> Option < Vec < String > > {
1724
- self . authors . clone ( )
1737
+ pub fn version ( & self ) -> CargoResult < semver:: Version > {
1738
+ self . version
1739
+ . clone ( )
1740
+ . map_or ( Err ( anyhow ! ( "[workspace.version] was not defined" ) ) , |d| {
1741
+ Ok ( d)
1742
+ } )
1725
1743
}
1726
1744
1727
- pub fn description ( & self ) -> Option < String > {
1728
- self . description . clone ( )
1745
+ pub fn authors ( & self ) -> CargoResult < Vec < String > > {
1746
+ self . authors
1747
+ . clone ( )
1748
+ . map_or ( Err ( anyhow ! ( "[workspace.authors] was not defined" ) ) , |d| {
1749
+ Ok ( d)
1750
+ } )
1729
1751
}
1730
1752
1731
- pub fn homepage ( & self ) -> Option < String > {
1732
- self . homepage . clone ( )
1753
+ pub fn description ( & self ) -> CargoResult < String > {
1754
+ self . description . clone ( ) . map_or (
1755
+ Err ( anyhow ! ( "[workspace.description] was not defined" ) ) ,
1756
+ |d| Ok ( d) ,
1757
+ )
1733
1758
}
1734
1759
1735
- pub fn documentation ( & self ) -> Option < String > {
1736
- self . documentation . clone ( )
1760
+ pub fn homepage ( & self ) -> CargoResult < String > {
1761
+ self . homepage
1762
+ . clone ( )
1763
+ . map_or ( Err ( anyhow ! ( "[workspace.homepage] was not defined" ) ) , |d| {
1764
+ Ok ( d)
1765
+ } )
1737
1766
}
1738
1767
1739
- pub fn readme ( & self ) -> Option < StringOrBool > {
1740
- self . readme . clone ( )
1768
+ pub fn documentation ( & self ) -> CargoResult < String > {
1769
+ self . documentation . clone ( ) . map_or (
1770
+ Err ( anyhow ! ( "[workspace.documentation] was not defined" ) ) ,
1771
+ |d| Ok ( d) ,
1772
+ )
1773
+ }
1774
+
1775
+ pub fn readme ( & self ) -> CargoResult < StringOrBool > {
1776
+ self . readme
1777
+ . clone ( )
1778
+ . map_or ( Err ( anyhow ! ( "[workspace.readme] was not defined" ) ) , |d| {
1779
+ Ok ( d)
1780
+ } )
1741
1781
}
1742
1782
1743
- pub fn keywords ( & self ) -> Option < Vec < String > > {
1744
- self . keywords . clone ( )
1783
+ pub fn keywords ( & self ) -> CargoResult < Vec < String > > {
1784
+ self . keywords
1785
+ . clone ( )
1786
+ . map_or ( Err ( anyhow ! ( "[workspace.keywords] was not defined" ) ) , |d| {
1787
+ Ok ( d)
1788
+ } )
1745
1789
}
1746
1790
1747
- pub fn categories ( & self ) -> Option < Vec < String > > {
1748
- self . categories . clone ( )
1791
+ pub fn categories ( & self ) -> CargoResult < Vec < String > > {
1792
+ self . categories . clone ( ) . map_or (
1793
+ Err ( anyhow ! ( "[workspace.categories] was not defined" ) ) ,
1794
+ |d| Ok ( d) ,
1795
+ )
1749
1796
}
1750
1797
1751
- pub fn license ( & self ) -> Option < String > {
1752
- self . license . clone ( )
1798
+ pub fn license ( & self ) -> CargoResult < String > {
1799
+ self . license
1800
+ . clone ( )
1801
+ . map_or ( Err ( anyhow ! ( "[workspace.license] was not defined" ) ) , |d| {
1802
+ Ok ( d)
1803
+ } )
1753
1804
}
1754
1805
1755
- pub fn license_file ( & self ) -> Option < String > {
1756
- self . license_file . clone ( )
1806
+ pub fn license_file ( & self ) -> CargoResult < String > {
1807
+ self . license_file . clone ( ) . map_or (
1808
+ Err ( anyhow ! ( "[workspace.license_file] was not defined" ) ) ,
1809
+ |d| Ok ( d) ,
1810
+ )
1757
1811
}
1758
1812
1759
- pub fn repository ( & self ) -> Option < String > {
1760
- self . repository . clone ( )
1813
+ pub fn repository ( & self ) -> CargoResult < String > {
1814
+ self . repository . clone ( ) . map_or (
1815
+ Err ( anyhow ! ( "[workspace.repository] was not defined" ) ) ,
1816
+ |d| Ok ( d) ,
1817
+ )
1761
1818
}
1762
1819
1763
- pub fn publish ( & self ) -> Option < VecStringOrBool > {
1764
- self . publish . clone ( )
1820
+ pub fn publish ( & self ) -> CargoResult < VecStringOrBool > {
1821
+ self . publish
1822
+ . clone ( )
1823
+ . map_or ( Err ( anyhow ! ( "[workspace.publish] was not defined" ) ) , |d| {
1824
+ Ok ( d)
1825
+ } )
1765
1826
}
1766
1827
1767
- pub fn edition ( & self ) -> Option < String > {
1768
- self . edition . clone ( )
1828
+ pub fn edition ( & self ) -> CargoResult < String > {
1829
+ self . edition
1830
+ . clone ( )
1831
+ . map_or ( Err ( anyhow ! ( "[workspace.edition] was not defined" ) ) , |d| {
1832
+ Ok ( d)
1833
+ } )
1769
1834
}
1770
1835
1771
- pub fn badges ( & self ) -> Option < BTreeMap < String , BTreeMap < String , String > > > {
1772
- self . badges . clone ( )
1836
+ pub fn badges ( & self ) -> CargoResult < BTreeMap < String , BTreeMap < String , String > > > {
1837
+ self . badges
1838
+ . clone ( )
1839
+ . map_or ( Err ( anyhow ! ( "[workspace.badges] was not defined" ) ) , |d| {
1840
+ Ok ( d)
1841
+ } )
1773
1842
}
1774
1843
}
0 commit comments