pub fn from_headers(headers: impl AsRef<Headers>) -> crate::Result<Option<Self>> {
        let headers = headers.as_ref();
        let mut rng = rand::thread_rng();

        let traceparent = match headers.get(TRACEPARENT) {
            Some(header) => header,
            None => return Ok(None),
        };
        let parts: Vec<&str> = traceparent.as_str().split('-').collect();

        Ok(Some(Self {
            id: rng.gen(),
            version: u8::from_str_radix(parts[0], 16)?,
            trace_id: u128::from_str_radix(parts[1], 16).status(400)?,
            parent_id: Some(u64::from_str_radix(parts[2], 16).status(400)?),
            flags: u8::from_str_radix(parts[3], 16).status(400)?,
        }))
    }
/// Create and return TraceContext object based on `traceparent` HTTP header.
///
/// # Errors
///
/// This function may error if the header is malformed. An error with a
/// status code of `400: Bad Request` will be generated.
///
/// # Examples
///
/// ```
/// # fn main() -> http_types::Result<()> {
/// #
/// use http_types::trace::TraceContext;
///
/// let mut res = http_types::Response::new(200);
/// res.insert_header(
///   "traceparent",
///   "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01"
/// );
///
/// let context = TraceContext::from_headers(&res)?.unwrap();
///
/// let trace_id = u128::from_str_radix("0af7651916cd43dd8448eb211c80319c", 16);
/// let parent_id = u64::from_str_radix("00f067aa0ba902b7", 16);
///
/// assert_eq!(context.trace_id(), trace_id.unwrap());
/// assert_eq!(context.parent_id(), parent_id.ok());
/// assert_eq!(context.sampled(), true);
/// #
/// # Ok(()) }
/// ```
Create and return TraceContext object based on `traceparent` HTTP header.
Create and return TraceContext object based on ` traceparent ` HTTP header .
pub fn from_headers(headers: impl AsRef<Headers>) -> crate::Result<Option<Self>> {
        let headers = headers.as_ref();
        let mut rng = rand::thread_rng();
        let traceparent = match headers.get(TRACEPARENT) {
            Some(header) => header,
            None => return Ok(None),
        };
        let parts: Vec<&str> = traceparent.as_str().split('-').collect();
        Ok(Some(Self {
            id: rng.gen(),
            version: u8::from_str_radix(parts[0], 16)?,
            trace_id: u128::from_str_radix(parts[1], 16).status(400)?,
            parent_id: Some(u64::from_str_radix(parts[2], 16).status(400)?),
            flags: u8::from_str_radix(parts[3], 16).status(400)?,
        }))
    }
pub fn from_headers ( headers : impl AsRef < Headers > ) -> crate :: Result < Option < Self > > { let headers = headers . as_ref ( ) ; let mut rng = rand :: thread_rng ( ) ; let traceparent = match headers . get ( TRACEPARENT ) { Some ( header ) => header , None => return Ok ( None ) , } ; let parts : Vec < & str > = traceparent . as_str ( ) . split ( '-' ) . collect ( ) ; Ok ( Some ( Self { id : rng . gen ( ) , version : u8 :: from_str_radix ( parts [ 0 ] , 16 ) ? , trace_id : u128 :: from_str_radix ( parts [ 1 ] , 16 ) . status ( 400 ) ? , parent_id : Some ( u64 :: from_str_radix ( parts [ 2 ] , 16 ) . status ( 400 ) ? ) , flags : u8 :: from_str_radix ( parts [ 3 ] , 16 ) . status ( 400 ) ? , } ) ) }
Create and return TraceContext object based on `traceparent` HTTP header.
Create and return TraceContext object based on ` traceparent ` HTTP header .
headers
impl AsRef<Headers>
headers
impl AsRef<Headers>
errors
This function may error if the header is malformed. An error with a
status code of `400: Bad Request` will be generated.
This function may error if the header is malformed . An error with a status code of ` 400 : Bad Request ` will be generated .
examples
None
fn main() -> http_types::result<()> {
use http_types::trace::TraceContext.



let context = TraceContext::from_headers(&res)?.unwrap().




use http_types :: trace :: TraceContext . let context = TraceContext :: from_headers ( &res ) ? . unwrap () .
ok(()) }
None