MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / to_rust_ident

Function to_rust_ident

crates/wit-bindgen/src/rust.rs:420–477  ·  view source on GitHub ↗

Translate `name` to a Rust `snake_case` identifier.

(name: &str)

Source from the content-addressed store, hash-verified

418
419/// Translate `name` to a Rust `snake_case` identifier.
420pub fn to_rust_ident(name: &str) -> String {
421 match name {
422 // Escape Rust keywords.
423 // Source: https://doc.rust-lang.org/reference/keywords.html
424 "as" => "as_".into(),
425 "break" => "break_".into(),
426 "const" => "const_".into(),
427 "continue" => "continue_".into(),
428 "crate" => "crate_".into(),
429 "else" => "else_".into(),
430 "enum" => "enum_".into(),
431 "extern" => "extern_".into(),
432 "false" => "false_".into(),
433 "fn" => "fn_".into(),
434 "for" => "for_".into(),
435 "if" => "if_".into(),
436 "impl" => "impl_".into(),
437 "in" => "in_".into(),
438 "let" => "let_".into(),
439 "loop" => "loop_".into(),
440 "match" => "match_".into(),
441 "mod" => "mod_".into(),
442 "move" => "move_".into(),
443 "mut" => "mut_".into(),
444 "pub" => "pub_".into(),
445 "ref" => "ref_".into(),
446 "return" => "return_".into(),
447 "self" => "self_".into(),
448 "static" => "static_".into(),
449 "struct" => "struct_".into(),
450 "super" => "super_".into(),
451 "trait" => "trait_".into(),
452 "true" => "true_".into(),
453 "type" => "type_".into(),
454 "unsafe" => "unsafe_".into(),
455 "use" => "use_".into(),
456 "where" => "where_".into(),
457 "while" => "while_".into(),
458 "async" => "async_".into(),
459 "await" => "await_".into(),
460 "dyn" => "dyn_".into(),
461 "abstract" => "abstract_".into(),
462 "become" => "become_".into(),
463 "box" => "box_".into(),
464 "do" => "do_".into(),
465 "final" => "final_".into(),
466 "macro" => "macro_".into(),
467 "override" => "override_".into(),
468 "priv" => "priv_".into(),
469 "typeof" => "typeof_".into(),
470 "unsized" => "unsized_".into(),
471 "virtual" => "virtual_".into(),
472 "yield" => "yield_".into(),
473 "try" => "try_".into(),
474 "gen" => "gen_".into(),
475 s => s.to_snake_case(),
476 }
477}

Callers 8

import_interfaceMethod · 0.85
exportMethod · 0.85
popMethod · 0.85
type_recordMethod · 0.85
rust_function_nameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected