MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / to_moonbit_ident

Method to_moonbit_ident

crates/moonbit/src/pkg.rs:393–415  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

391
392impl ToMoonBitIdent for str {
393 fn to_moonbit_ident(&self) -> String {
394 // Escape MoonBit keywords and reserved keywords
395 match self {
396 // Keywords
397 "as" | "else" | "extern" | "fn" | "fnalias" | "if" | "let" | "const" | "match" | "using"
398 | "mut" | "type" | "typealias" | "struct" | "enum" | "trait" | "traitalias" | "derive"
399 | "while" | "break" | "continue" | "import" | "return" | "throw" | "raise" | "try" | "catch"
400 | "pub" | "priv" | "readonly" | "true" | "false" | "_" | "test" | "loop" | "for" | "in" | "impl"
401 | "with" | "guard" | "async" | "is" | "suberror" | "and" | "letrec" | "enumview" | "noraise"
402 | "defer" | "init" | "main"
403 // Reserved keywords
404 | "module" | "move" | "ref" | "static" | "super" | "unsafe" | "use" | "where" | "await"
405 | "dyn" | "abstract" | "do" | "final" | "macro" | "override" | "typeof" | "virtual" | "yield"
406 | "local" | "method" | "alias" | "assert" | "package" | "recur" | "isnot" | "define" | "downcast"
407 | "inherit" | "member" | "namespace" | "upcast" | "void" | "lazy" | "include" | "mixin"
408 | "protected" | "sealed" | "constructor" | "atomic" | "volatile" | "anyframe" | "anytype"
409 | "asm" | "comptime" | "errdefer" | "export" | "opaque" | "orelse" | "resume" | "threadlocal"
410 | "unreachable" | "dynclass" | "dynobj" | "dynrec" | "var" | "finally" | "noasync" => {
411 format!("{self}_")
412 }
413 _ => self.strip_prefix("[async]").unwrap_or(self).to_snake_case(),
414 }
415 }
416}
417
418pub(crate) trait ToMoonBitTypeIdent: ToOwned {

Callers 4

mbt_sigMethod · 0.80
importMethod · 0.80
exportMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected