File tree Expand file tree Collapse file tree 4 files changed +59
-42
lines changed Expand file tree Collapse file tree 4 files changed +59
-42
lines changed Original file line number Diff line number Diff line change
1
+ pub mod gemtext;
2
+ pub use gemtext:: Gemtext ;
3
+
1
4
/// [List item](https://geminiprotocol.net/docs/gemtext-specification.gmi#list-items) tag
2
5
pub const TAG : char = '*' ;
3
6
@@ -24,33 +27,12 @@ impl List {
24
27
}
25
28
}
26
29
27
- pub trait Gemtext {
28
- /// Get [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) value for `Self`
29
- fn as_value ( & self ) -> Option < & str > ;
30
- /// Convert `Self` to [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) line
31
- fn to_source ( & self ) -> String ;
32
- }
33
-
34
- impl Gemtext for str {
35
- fn as_value ( & self ) -> Option < & str > {
36
- self . strip_prefix ( TAG ) . map ( |s| s. trim ( ) )
37
- }
38
- fn to_source ( & self ) -> String {
39
- format ! ( "{TAG} {}" , self . trim( ) )
40
- }
41
- }
42
-
43
30
#[ test]
44
31
fn test ( ) {
45
32
const SOURCE : & str = "* Item" ;
46
33
const VALUE : & str = "Item" ;
47
34
48
- // test `List`
49
35
let list = List :: parse ( SOURCE ) . unwrap ( ) ;
50
36
assert_eq ! ( list. value, VALUE ) ;
51
37
assert_eq ! ( list. to_source( ) , SOURCE ) ;
52
-
53
- // test `Gemtext`
54
- assert_eq ! ( SOURCE . as_value( ) , Some ( VALUE ) ) ;
55
- assert_eq ! ( VALUE . to_source( ) , SOURCE )
56
38
}
Original file line number Diff line number Diff line change
1
+ use super :: TAG ;
2
+
3
+ pub trait Gemtext {
4
+ /// Get [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) value for `Self`
5
+ fn as_value ( & self ) -> Option < & str > ;
6
+ /// Convert `Self` to [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) line
7
+ fn to_source ( & self ) -> String ;
8
+ }
9
+
10
+ impl Gemtext for str {
11
+ fn as_value ( & self ) -> Option < & str > {
12
+ self . strip_prefix ( TAG ) . map ( |s| s. trim ( ) )
13
+ }
14
+ fn to_source ( & self ) -> String {
15
+ format ! ( "{TAG} {}" , self . trim( ) )
16
+ }
17
+ }
18
+
19
+ #[ test]
20
+ fn test ( ) {
21
+ const SOURCE : & str = "* Item" ;
22
+ const VALUE : & str = "Item" ;
23
+
24
+ assert_eq ! ( SOURCE . as_value( ) , Some ( VALUE ) ) ;
25
+ assert_eq ! ( VALUE . to_source( ) , SOURCE )
26
+ }
Original file line number Diff line number Diff line change
1
+ pub mod gemtext;
2
+ pub use gemtext:: Gemtext ;
3
+
1
4
/// [Quote item](https://geminiprotocol.net/docs/gemtext-specification.gmi#quote-lines) tag
2
5
pub const TAG : char = '>' ;
3
6
@@ -24,33 +27,13 @@ impl Quote {
24
27
}
25
28
}
26
29
27
- pub trait Gemtext {
28
- /// Get [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) value for `Self`
29
- fn as_value ( & self ) -> Option < & str > ;
30
- /// Convert `Self` to [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) line
31
- fn to_source ( & self ) -> String ;
32
- }
33
-
34
- impl Gemtext for str {
35
- fn as_value ( & self ) -> Option < & str > {
36
- self . strip_prefix ( TAG ) . map ( |s| s. trim ( ) )
37
- }
38
- fn to_source ( & self ) -> String {
39
- format ! ( "{TAG} {}" , self . trim( ) )
40
- }
41
- }
42
-
43
30
#[ test]
44
31
fn test ( ) {
45
32
const SOURCE : & str = "> Quote" ;
46
33
const VALUE : & str = "Quote" ;
47
34
48
- // test `Quote`
49
35
let quote = Quote :: parse ( SOURCE ) . unwrap ( ) ;
36
+
50
37
assert_eq ! ( quote. value, VALUE ) ;
51
38
assert_eq ! ( quote. to_source( ) , SOURCE ) ;
52
-
53
- // test `Gemtext`
54
- assert_eq ! ( SOURCE . as_value( ) , Some ( VALUE ) ) ;
55
- assert_eq ! ( VALUE . to_source( ) , SOURCE )
56
39
}
Original file line number Diff line number Diff line change
1
+ use super :: TAG ;
2
+
3
+ pub trait Gemtext {
4
+ /// Get [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) value for `Self`
5
+ fn as_value ( & self ) -> Option < & str > ;
6
+ /// Convert `Self` to [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) line
7
+ fn to_source ( & self ) -> String ;
8
+ }
9
+
10
+ impl Gemtext for str {
11
+ fn as_value ( & self ) -> Option < & str > {
12
+ self . strip_prefix ( TAG ) . map ( |s| s. trim ( ) )
13
+ }
14
+ fn to_source ( & self ) -> String {
15
+ format ! ( "{TAG} {}" , self . trim( ) )
16
+ }
17
+ }
18
+
19
+ #[ test]
20
+ fn test ( ) {
21
+ const SOURCE : & str = "> Quote" ;
22
+ const VALUE : & str = "Quote" ;
23
+
24
+ assert_eq ! ( SOURCE . as_value( ) , Some ( VALUE ) ) ;
25
+ assert_eq ! ( VALUE . to_source( ) , SOURCE )
26
+ }
You can’t perform that action at this time.
0 commit comments