[−][src]Struct TCFSMFTTTCS::TysCountingFSMForTyTtClusterSeq
Finite State Machine for counting :ty TokenTree clusters in :ty TokenStreams and other :ty TokenTree cluster sequences
Methods
impl<T> TysCountingFSMForTyTtClusterSeq<T>
[src]
pub fn get_count(self) -> T
[src]
Returns the number of counted :ty TokenTree clusters
Examples
Basic usage:
extern crate proc_macro; extern crate proc_macro2; extern crate quote; extern crate proc_macro_hack; extern crate tys_counting_fsm_for_ty_tt_cluster_seq; use quote::quote; use tys_counting_fsm_for_ty_tt_cluster_seq::TysCountingFSMForTyTtClusterSeq; // TODO: Switch out from proc_macro_hack and edit documentation when //"error: procedural macros cannot be expanded to expressions" is resloved. // note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information #[proc_macro_hack] pub unsafe fn unsafe_count_tys_in_ty_ts() { let tys_count :usize = proc_macro2::TokenStream::from(input) .into_iter() .fold(TysCountingFSMForTyTtClusterSeq::<usize>::new(), |ty_counting_fsm, tt| unsafe { // proof of safety ty_counting_fsm.unsafe_transition(tt) }) .get_count(); let expanded_tt = quote!{#tts_count}; proc_macro::TokenStream::from(expanded_tt) }
impl<T> TysCountingFSMForTyTtClusterSeq<T> where
T: Default,
[src]
T: Default,
pub fn new() -> Self
[src]
Constructs a new TysCountingFSMForTyTtClusterSeq
Newly constructed TysCountingFSMForTyTtClusterSeq returns Default::default with TysCountingFSMForTyTtClusterSeq::<T>::get_count
Examples
Basic usage:
extern crate tys_counting_fsm_for_ty_tt_cluster_seq; use tys_counting_fsm_for_ty_tt_cluster_seq::TysCountingFSMForTyTtClusterSeq; let tys_counting_fsm_for_ty_tt_cluster_seq = TysCountingFSMForTyTtClusterSeq::<usize>::new(); let initial_value :usize = tys_counting_fsm_for_ty_tt_cluster_seq.get_count(); assert_eq!(0, initial_value);
impl<T> TysCountingFSMForTyTtClusterSeq<T> where
T: AddAssign + One,
[src]
T: AddAssign + One,
pub unsafe fn unsafe_transition(self, tt: TokenTree) -> Self
[src]
Returns a mutable reference to the TysCountingFSMForTyTtClusterSeq in the transitioned (modified) state. Internally, counts :ty TokenTree clusters in the given TokenTree sequence assuming it is a [:ty TokenTree sequence] and using Signs of :ty TokenTree clusters` boundaries in :ty TokenTree sequence. Guarantees to correctly maintain count of encountered :ty TokenTree clusters only for traversed paths that are prefixes of [:ty TokenTree sequence].
Arguments
tt
- next TokenTree on the prefix-path of a :ty TokenTree cluster sequence
Safety
tt
must be on the prefix-path of a :ty TokenTree cluster sequence. For example,
any prefix of [:ty TokenStream]
Examples
Basic usage:
extern crate proc_macro; extern crate proc_macro2; extern crate quote; extern crate proc_macro_hack; extern crate tys_counting_fsm_for_ty_tt_cluster_seq; use quote::quote; use tys_counting_fsm_for_ty_tt_cluster_seq::TysCountingFSMForTyTtClusterSeq; // TODO: Switch out from proc_macro_hack and edit documentation when //"error: procedural macros cannot be expanded to expressions" is resloved. // note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information #[proc_macro_hack] pub unsafe fn unsafe_count_tys_in_ty_ts() { let tys_count :usize = proc_macro2::TokenStream::from(input) .into_iter() .fold(TysCountingFSMForTyTtClusterSeq::<usize>::new(), |ty_counting_fsm, tt| unsafe { // proof of safety ty_counting_fsm.unsafe_transition(tt) }) .get_count(); let expanded_tt = quote!{#tts_count}; proc_macro::TokenStream::from(expanded_tt) }
pub unsafe fn unsafe_into_iter_transition(self, ts: TokenStream) -> Self
[src]
Returns a mutable reference to the TysCountingFSMForTyTtClusterSeq in the transitioned (modified) state. Internally, counts :ty TokenTree clusters in the given TokenStream assuming it is a :ty TokenStream and using Signs of :ty TokenTree clusters` boundaries in :ty TokenTree sequence. Guarantees to correctly maintain count of encountered :ty TokenTree clusters only for traversed paths that are prefixes of [:ty TokenTree sequence].
Arguments
ts
- presumably, not just a regular TokenStream, but a :ty TokenStream
Safety
ts
must be a :ty TokenStream
Example
extern crate proc_macro; extern crate proc_macro2; extern crate quote; extern crate proc_macro_hack; extern crate tys_counting_fsm_for_ty_tt_cluster_seq; use quote::quote; use tys_counting_fsm_for_ty_tt_cluster_seq::TysCountingFSMForTyTtClusterSeq; // TODO: Switch out from proc_macro_hack and edit documentation when //"error: procedural macros cannot be expanded to expressions" is resloved. // note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information #[proc_macro_hack] pub unsafe fn unsafe_count_tys_in_ty_ts() { let tys_counting_fsm_for_ty_tt_cluster_seq = TysCountingFSMForTyTtClusterSeq::<usize>::new(); let tys_count :usize = unsafe { tys_counting_fsm_for_ty_tt_cluster_seq.unsafe_into_iter_transition proc_macro2::TokenStream::from(input) } let tys_count :usize = proc_macro2::TokenStream::from(input) .into_iter() .fold(TysCountingFSMForTyTtClusterSeq::<usize>::new(), |ty_counting_fsm, tt| unsafe { // proof of safety ty_counting_fsm.unsafe_transition(tt) }) .get_count(); let expanded_tt = quote!{#tts_count}; proc_macro::TokenStream::from(expanded_tt) }
Trait Implementations
impl<T: Clone> Clone for TysCountingFSMForTyTtClusterSeq<T>
[src]
fn clone(&self) -> TysCountingFSMForTyTtClusterSeq<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Copy> Copy for TysCountingFSMForTyTtClusterSeq<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for TysCountingFSMForTyTtClusterSeq<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for TysCountingFSMForTyTtClusterSeq<T> where
T: Send,
T: Send,
impl<T> Sync for TysCountingFSMForTyTtClusterSeq<T> where
T: Sync,
T: Sync,
impl<T> Unpin for TysCountingFSMForTyTtClusterSeq<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for TysCountingFSMForTyTtClusterSeq<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,