pub(crate) fn process_stack(&self, stack: &mut Vec<Option<NonZeroUsize>>) -> Result<(), Error> {
        let is_attr = matches!(self, Attribute(_));
        let is_stream_end = matches!(self, StreamEnd);

        // don't count the attribute element on counting sequence length
        if !is_attr {
            match (is_stream_end, stack.pop().unwrap()) {
                // stream is ended
                (true, None) => {}
                // stream not ended yet
                (false, None) => stack.push(None),
                // unexpected stream end token
                (true, Some(_)) => return Err(Error::UnexpectedStreamEnd),
                (false, Some(len)) => match NonZeroUsize::new(len.get() - 1) {
                    // the finite sequence is ended
                    None => {}
                    // advancing the finite sequence
                    Some(len) => stack.push(Some(len)),
                },
            }
        }

        // push the protocol stack frame if needed
        match self {
            // scalars don't push any frame
            Blob(Some(_)) | BlobStream(_) | Simple(_) | SimpleError(_) | Number(_) | Null
            | Double(_) | Boolean(_) | BlobError(_) | Verbatim(_) | BigNumber(_) | StreamEnd => {}
            // sequences push frame if they're not empty
            Array(Some(len)) | Set(Some(len)) | Attribute(len) | Push(len) => {
                if let Some(len) = NonZeroUsize::new(*len) {
                    stack.push(Some(len))
                }
            }
            // Map pushes the double of its length
            Map(Some(len)) => {
                if let Some(len) = NonZeroUsize::new(len * 2) {
                    stack.push(Some(len))
                }
            }
            // streaming sequence push frame without length
            Array(None) | Blob(None) | Map(None) | Set(None) => stack.push(None),
        }

        Ok(())
    }
/// Process recursive type stack with self token.
/// Start with the stack with `vec![Some(amt)]`
/// where `amt` is the amount of token trees
/// and keep call this function with new tokens
/// until the stack is empty.
Process recursive type stack with self token.
Start with the stack with `vec![Some(amt)]`
where `amt` is the amount of token trees
and keep call this function with new tokens
until the stack is empty.
Process recursive type stack with self token . Start with the stack with ` vec! [ Some ( amt ) ] ` where ` amt ` is the amount of token trees and keep call this function with new tokens until the stack is empty .
pub(crate) fn process_stack(&self, stack: &mut Vec<Option<NonZeroUsize>>) -> Result<(), Error> {
        let is_attr = matches!(self, Attribute(_));
        let is_stream_end = matches!(self, StreamEnd);
        // don't count the attribute element on counting sequence length
        if !is_attr {
            match (is_stream_end, stack.pop().unwrap()) {
                // stream is ended
                (true, None) => {}
                // stream not ended yet
                (false, None) => stack.push(None),
                // unexpected stream end token
                (true, Some(_)) => return Err(Error::UnexpectedStreamEnd),
                (false, Some(len)) => match NonZeroUsize::new(len.get() - 1) {
                    // the finite sequence is ended
                    None => {}
                    // advancing the finite sequence
                    Some(len) => stack.push(Some(len)),
                },
            }
        }
        // push the protocol stack frame if needed
        match self {
            // scalars don't push any frame
            Blob(Some(_)) | BlobStream(_) | Simple(_) | SimpleError(_) | Number(_) | Null
            | Double(_) | Boolean(_) | BlobError(_) | Verbatim(_) | BigNumber(_) | StreamEnd => {}
            // sequences push frame if they're not empty
            Array(Some(len)) | Set(Some(len)) | Attribute(len) | Push(len) => {
                if let Some(len) = NonZeroUsize::new(*len) {
                    stack.push(Some(len))
                }
            }
            // Map pushes the double of its length
            Map(Some(len)) => {
                if let Some(len) = NonZeroUsize::new(len * 2) {
                    stack.push(Some(len))
                }
            }
            // streaming sequence push frame without length
            Array(None) | Blob(None) | Map(None) | Set(None) => stack.push(None),
        }
        Ok(())
    }
pub ( crate ) fn process_stack ( & self , stack : & mut Vec < Option < NonZeroUsize > > ) -> Result < ( ) , Error > { let is_attr = matches ! ( self Attribute ( ) ) ; let is_stream_end = matches ! ( self StreamEnd ) ; // don't count the attribute element on counting sequence length if ! is_attr { match ( is_stream_end , stack . pop ( ) . unwrap ( ) ) { // stream is ended ( true , None ) => { } // stream not ended yet ( false , None ) => stack . push ( None ) , // unexpected stream end token ( true , Some ( _ ) ) => return Err ( Error :: UnexpectedStreamEnd ) , ( false , Some ( len ) ) => match NonZeroUsize :: new ( len . get ( ) - 1 ) { // the finite sequence is ended None => { } // advancing the finite sequence Some ( len ) => stack . push ( Some ( len ) ) , } , } } // push the protocol stack frame if needed match self { // scalars don't push any frame Blob ( Some ( _ ) ) | BlobStream ( _ ) | Simple ( _ ) | SimpleError ( _ ) | Number ( _ ) | Null | Double ( _ ) | Boolean ( _ ) | BlobError ( _ ) | Verbatim ( _ ) | BigNumber ( _ ) | StreamEnd => { } // sequences push frame if they're not empty Array ( Some ( len ) ) | Set ( Some ( len ) ) | Attribute ( len ) | Push ( len ) => { if let Some ( len ) = NonZeroUsize :: new ( * len ) { stack . push ( Some ( len ) ) } } // Map pushes the double of its length Map ( Some ( len ) ) => { if let Some ( len ) = NonZeroUsize :: new ( len * 2 ) { stack . push ( Some ( len ) ) } } // streaming sequence push frame without length Array ( None ) | Blob ( None ) | Map ( None ) | Set ( None ) => stack . push ( None ) , } Ok ( ( ) ) }
Process recursive type stack with self token.
Process recursive type stack with self token .
&self
stack
&mut Vec<Option<NonZeroUsize>>