Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/diplomat/src/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 1 kB image not shown  

Quelle  transparent_convert.rs

  Sprache: Rust
 

use quote::quote;
use syn::*;

pub fn gen_transparent_convert(s: ItemStruct) -> proc_macro2::TokenStream {
    let mut fields = s.fields.iter();
    let field1 = if let Some(field1) = fields.next() {
        &field1.ty
    } else {
        panic!("#[diplomat::transparent_convert] only allowed on structs with a single field")
    };

    if fields.next().is_some() {
        panic!("#[diplomat::transparent_convert] only allowed on structs with a single field")
    }
    let struct_name = &s.ident;
    let (impl_generics, ty_generics, _) = s.generics.split_for_impl();
    let mut impl_generics: Generics = parse_quote!(#impl_generics);
    let custom_lifetime: GenericParam = parse_quote!('transparent_convert_outer);
    impl_generics.params.push(custom_lifetime);
    quote! {
        impl #impl_generics #struct_name #ty_generics {
            // can potentially add transparent_convert_owned, _mut later
            pub(cratefn transparent_convert(from: &'transparent_convert_outer #field1) -> &'transparent_convert_outer Self {
                // Safety: This is safe because the caller of gen_transparent_convert
                // adds a repr(transparent) to the struct.
                unsafe {
                    &*(from as *const #field1 as *const Self)
                }
            }
        }
    }
}

Messung V0.5 in Prozent
C=72 H=95 G=83

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.