Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/quote/src/spanned.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / quote / src / spanned.rs` 49 lines ยท 1081 bytes Raw Blame History 1 use crate::ToTokens; 2 use proc_macro2::extra::DelimSpan; 3 use proc_macro2::{Span, TokenStream}; 4 5 // Not public API other than via the syn crate. Use syn::spanned::Spanned. 6 pub trait Spanned: private::Sealed { 7 fn __span(&self) -> Span; 8 } 9 10 impl Spanned for Span { 11 fn __span(&self) -> Span { 12 *self 13 } 14 } 15 16 impl Spanned for DelimSpan { 17 fn __span(&self) -> Span { 18 self.join() 19 } 20 } 21 22 impl Spanned for T { 23 fn __span(&self) -> Span { 24 join_spans(self.into_token_stream()) 25 } 26 } 27 28 fn join_spans(tokens: TokenStream) -> Span { 29 let mut iter = tokens.into_iter().map(|tt| tt.span()); 30 31 let Some(first) = iter.next() else { 32 return Span::call_site(); 33 }; 34 35 iter.fold(None, |_prev, next| Some(next)) 36 .and_then(|last| first.join(last)) 37 .unwrap_or(first) 38 } 39 40 mod private { 41 use crate::ToTokens; 42 use proc_macro2::extra::DelimSpan; 43 use proc_macro2::Span; 44 45 pub trait Sealed {} 46 impl Sealed for Span {} 47 impl Sealed for DelimSpan {} 48 impl Sealed for T {} 49 }