Sha256: ea6a8d0c1a33521163e5546463f68f6dbda0d35a59e75597be6bf04e0b7b23ad

Contents?: true

Size: 1.34 KB

Versions: 30

Compression:

Stored size: 1.34 KB

Contents

use proc_macro2::{Ident, Span, TokenStream};
use quote::quote_spanned;
use syn::punctuated::Punctuated;
use syn::{Token, TypeParamBound};

pub type Supertraits = Punctuated<TypeParamBound, Token![+]>;

pub enum InferredBound {
    Send,
    Sync,
}

pub fn has_bound(supertraits: &Supertraits, bound: &InferredBound) -> bool {
    for supertrait in supertraits {
        if let TypeParamBound::Trait(supertrait) = supertrait {
            if supertrait.path.is_ident(bound)
                || supertrait.path.segments.len() == 3
                    && (supertrait.path.segments[0].ident == "std"
                        || supertrait.path.segments[0].ident == "core")
                    && supertrait.path.segments[1].ident == "marker"
                    && supertrait.path.segments[2].ident == *bound
            {
                return true;
            }
        }
    }
    false
}

impl InferredBound {
    fn as_str(&self) -> &str {
        match self {
            InferredBound::Send => "Send",
            InferredBound::Sync => "Sync",
        }
    }

    pub fn spanned_path(&self, span: Span) -> TokenStream {
        let ident = Ident::new(self.as_str(), span);
        quote_spanned!(span=> ::core::marker::#ident)
    }
}

impl PartialEq<InferredBound> for Ident {
    fn eq(&self, bound: &InferredBound) -> bool {
        self == bound.as_str()
    }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-23.0.2 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-22.0.0 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-21.0.1 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-20.0.2 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-20.0.0 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-18.0.3 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-17.0.1 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-17.0.0 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-16.0.0 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-15.0.1 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-15.0.0 ./ext/cargo-vendor/async-trait-0.1.77/src/bound.rs
wasmtime-14.0.4 ./ext/cargo-vendor/async-trait-0.1.74/src/bound.rs
wasmtime-14.0.3 ./ext/cargo-vendor/async-trait-0.1.74/src/bound.rs
wasmtime-14.0.1 ./ext/cargo-vendor/async-trait-0.1.74/src/bound.rs
wasmtime-14.0.0 ./ext/cargo-vendor/async-trait-0.1.74/src/bound.rs
wasmtime-13.0.0 ./ext/cargo-vendor/async-trait-0.1.73/src/bound.rs
wasmtime-12.0.1 ./ext/cargo-vendor/async-trait-0.1.73/src/bound.rs
wasmtime-12.0.0 ./ext/cargo-vendor/async-trait-0.1.73/src/bound.rs
wasmtime-11.0.0 ./ext/cargo-vendor/async-trait-0.1.73/src/bound.rs
wasmtime-10.0.1 ./ext/cargo-vendor/async-trait-0.1.72/src/bound.rs