🦠 The Definitive Gemini Protocol Toolkit
gemini gemini-protocol gemtext parser zero-dependency toolkit ast converter html markdown cli networking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(ast): clean up from_*s for ast

Fuwn b52ad3f7 a6a71f66

+29 -3
+28 -2
crates/germ/src/ast/container.rs
··· 31 31 } 32 32 33 33 impl Ast { 34 - /// Build an AST tree from Gemtext. 34 + /// Build an AST tree from Gemtext 35 + /// 36 + /// # Example 37 + /// 38 + /// ```rust 39 + /// let _ = germ::ast::Ast::from_string(r#"=> gemini://gem.rest/ GemRest"#); 40 + /// ``` 41 + #[must_use] 42 + pub fn from_owned(value: &(impl AsRef<str> + ?Sized)) -> Self { 43 + Self::from_value(value.as_ref()) 44 + } 45 + 46 + /// Build an AST tree from Gemtext 35 47 /// 36 48 /// # Example 37 49 /// ··· 39 51 /// let _ = germ::ast::Ast::from_string(r#"=> gemini://gem.rest/ GemRest"#); 40 52 /// ``` 41 53 #[must_use] 42 - pub fn from_string(source: &str) -> Self { 54 + #[allow(clippy::needless_pass_by_value)] 55 + pub fn from_string(value: (impl Into<String> + ?Sized)) -> Self { 56 + Self::from_value(&value.into()) 57 + } 58 + 59 + /// Build an AST tree from a value 60 + /// 61 + /// # Example 62 + /// 63 + /// ```rust 64 + /// let _ = germ::ast::Ast::from_value(r#"=> gemini://gem.rest/ GemRest"#); 65 + /// ``` 66 + #[must_use] 67 + pub fn from_value(value: &(impl ToString + ?Sized)) -> Self { 43 68 let mut ast = vec![]; 44 69 let mut in_preformatted = false; 45 70 let mut in_list = false; 71 + let source = value.to_string(); 46 72 let mut lines = source.lines(); 47 73 48 74 // Iterate over all lines in the Gemtext `source`
+1 -1
crates/germ/src/convert.rs
··· 69 69 /// ``` 70 70 #[must_use] 71 71 pub fn from_string(source: &str, target: &Target) -> String { 72 - from_ast(&Ast::from_string(source), target) 72 + from_ast(&Ast::from_owned(&source), target) 73 73 }