diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-19 01:16:35 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-19 01:16:35 +0100 |
| commit | b4b022940b908d8fe490b9f4f68bc60dcfb76cd2 (patch) | |
| tree | bc93a2f51295f97f971466ab87bdd763c0ed6002 /src | |
| parent | ba384e5bb6c2455eb431f6e1fcc8b98aca1e9879 (diff) | |
Syntax and example sections
Diffstat (limited to 'src')
| -rw-r--r-- | src/font/book.rs | 4 | ||||
| -rw-r--r-- | src/font/mod.rs | 6 | ||||
| -rw-r--r-- | src/model/func.rs | 6 | ||||
| -rw-r--r-- | src/model/library.rs | 2 |
4 files changed, 15 insertions, 3 deletions
diff --git a/src/font/book.rs b/src/font/book.rs index 2ad30f1d..38dfee1d 100644 --- a/src/font/book.rs +++ b/src/font/book.rs @@ -170,7 +170,7 @@ bitflags::bitflags! { impl FontInfo { /// Compute metadata for all fonts in the given data. - pub fn from_data(data: &[u8]) -> impl Iterator<Item = FontInfo> + '_ { + pub fn iter(data: &[u8]) -> impl Iterator<Item = FontInfo> + '_ { let count = ttf_parser::fonts_in_collection(data).unwrap_or(1); (0..count).filter_map(move |index| { let ttf = ttf_parser::Face::parse(data, index).ok()?; @@ -179,7 +179,7 @@ impl FontInfo { } /// Compute metadata for a single ttf-parser face. - pub fn from_ttf(ttf: &ttf_parser::Face) -> Option<Self> { + pub(super) fn from_ttf(ttf: &ttf_parser::Face) -> Option<Self> { // We cannot use Name ID 16 "Typographic Family", because for some // fonts it groups together more than just Style / Weight / Stretch // variants (e.g. Display variants of Noto fonts) and then some diff --git a/src/font/mod.rs b/src/font/mod.rs index 98875d8f..13189b6d 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -69,6 +69,12 @@ impl Font { }))) } + /// Parse all fonts in the given data. + pub fn iter(data: Buffer) -> impl Iterator<Item = Self> { + let count = ttf_parser::fonts_in_collection(&data).unwrap_or(1); + (0..count).filter_map(move |index| Self::new(data.clone(), index)) + } + /// The underlying buffer. pub fn data(&self) -> &Buffer { &self.0.data diff --git a/src/model/func.rs b/src/model/func.rs index 46befd77..fb8b3dd0 100644 --- a/src/model/func.rs +++ b/src/model/func.rs @@ -214,6 +214,10 @@ pub struct FuncInfo { pub tags: &'static [&'static str], /// Documentation for the function. pub docs: &'static str, + /// The source code of an example, if any. + pub example: Option<&'static str>, + /// Documentation about this function's syntax, if it has syntax. + pub syntax: Option<&'static str>, /// Details about the function's parameters. pub params: Vec<ParamInfo>, } @@ -232,6 +236,8 @@ pub struct ParamInfo { pub name: &'static str, /// Documentation for the parameter. pub docs: &'static str, + /// The source code of an example, if any. + pub example: Option<&'static str>, /// Valid values for the parameter. pub cast: CastInfo, /// Is the parameter positional? diff --git a/src/model/library.rs b/src/model/library.rs index 83310610..8b767b0e 100644 --- a/src/model/library.rs +++ b/src/model/library.rs @@ -122,7 +122,7 @@ pub static LANG_ITEMS: OnceCell<LangItems> = OnceCell::new(); /// break incremental, but only when different sets of lang items are used in /// the same program. For this reason, if this function is called multiple /// times, the items must be the same. -pub(crate) fn set_lang_items(items: LangItems) { +pub fn set_lang_items(items: LangItems) { if let Err(items) = LANG_ITEMS.set(items) { let first = hash128(LANG_ITEMS.get().unwrap()); let second = hash128(&items); |
