PageSourceSearch

https://noir-lang.org/docs/assets/js/1d85cd76.fae99bee.js

js noir-lang.org collected 2026-10-03 22:51:13 UTC 8,606 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkdocs=globalThis.webpackChunkdocs||[]).push([[1307],{40740(e,t,n){n.r(t),n.d(t,{assets:()=>o,contentTitle:()=>a,default:()=>m,frontMatter:()=>l,metadata:()=>r,toc:()=>c});const r=JSON.parse('{"id":"libraries/standard_library/meta/ctstring","title":"CtString","description":"Compile-time, dynamically sized strings for `comptime`\u2014build, append, and emit quoted string literals.","source":"@site/processed-docs/libraries/standard_library/meta/ctstring.md","sourceDirName":"libraries/standard_library/meta","slug":"/libraries/standard_library/meta/ctstring","permalink":"/docs/dev/libraries/standard_library/meta/ctstring","draft":false,"unlisted":false,"editUrl":"https://github.com/noir-lang/noir/edit/master/docs/docs/libraries/standard_library/meta/ctstring.md","tags":[],"version":"current","frontMatter":{"title":"CtString","description":"Compile-time, dynamically sized strings for `comptime`\u2014build, append, and emit quoted string literals."},"sidebar":"sidebar","previous":{"title":"Metaprogramming","permalink":"/docs/dev/libraries/standard_library/meta/"},"next":{"title":"Expr","permalink":"/docs/dev/libraries/standard_library/meta/expr"}}');var s=n(74848),i=n(28453);const l={title:"CtString",description:"Compile-time, dynamically sized strings for `comptime`\u2014build, append, and emit quoted string literals."},a=void 0,o={},c=[{value:"Traits",id:"traits",level:2},{value:"AsCtString",id:"asctstring",level:3},{value:"Methods",id:"methods",level:2},{value:"new",id:"new",level:3},{value:"append_str",id:"append_str",level:3},{value:"append_fmtstr",id:"append_fmtstr",level:3},{value:"as_quoted_str",id:"as_quoted_str",level:3},{value:"Trait Implementations",id:"trait-implementations",level:2}];function d(e){const t={a:"a",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",sub:"sub",sup:"sup",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"std::meta::ctstring"})," contains methods on the built-in ",(0,s.jsx)(t.code,{children:"CtString"})," type which is\na compile-time, dynamically-sized string type. Compared to ",(0,s.jsx)(t.code,{children:"str<N>"})," and ",(0,s.jsx)(t.code,{children:"fmtstr<N, T>"}),",\n",(0,s.jsx)(t.code,{children:"CtString"})," is useful because its size does not need to be specified in its type. This\ncan be used for formatting items at compile-time or general string handling in ",(0,s.jsx)(t.code,{children:"comptime"}),"\ncode."]}),"\n",(0,s.jsxs)(t.p,{children:["Since ",(0,s.jsx)(t.code,{children:"fmtstr"}),"s can be converted into ",(0,s.jsx)(t.code,{children:"CtString"}),"s, you can make use of their formatting\nabilities in CtStrings by formatting in ",(0,s.jsx)(t.code,{children:"fmtstr"}),"s then converting the result to a CtString\nafterward."]}),"\n",(0,s.jsx)(t.h2,{id:"traits",children:"Traits"}),"\n",(0,s.jsx)(t.h3,{id:"asctstring",children:"AsCtString"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",metastring:'title="as-ctstring" showLineNumbers ',children:"pub trait AsCtString {\n    comptime fn as_ctstring(self) -> CtString;\n}\n"})}),"\n",(0,s.jsxs)(t.blockquote,{children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.sub,{children:(0,s.jsx)(t.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/meta/ctstring.nr#L43-L47",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/meta/ctstring.nr#L43-L47"})})})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Converts an object into a compile-time string."}),"\n",(0,s.jsx)(t.p,{children:"Implementations:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",children:"impl<let N: u32> AsCtString for str<N> { ... }\nimpl<let N: u32, T> AsCtString for fmtstr<N, T> { ... }\n"})}),"\n",(0,s.jsx)(t.h2,{id:"methods",children:"Methods"}),"\n",(0,s.jsx)(t.h3,{id:"new",children:"new"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",metastring:'title="new" showLineNumbers ',children:"pub comptime fn new() -> Self {\n"})}),"\n",(0,s.jsxs)(t.blockquote,{children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.sub,{children:(0,s.jsx)(t.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/meta/ctstring.nr#L4-L6",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/meta/ctstring.nr#L4-L6"})})})}),"\n"]}),"\n",(0,s.jsxs)(t.p,{children:["Creates an empty ",(0,s.jsx)(t.code,{children:"CtString"}),"."]}),"\n",(0,s.jsx)(t.h3,{id:"append_str",children:"append_str"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",metastring:'title="append_str" showLineNumbers ',children:"pub comptime fn append_str<let N: u32>(self, s: str<N>) -> Self {\n"})}),"\n",(0,s.jsxs)(t.blockquote,{children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.sub,{children:(0,s.jsx)(t.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/meta/ctstring.nr#L12-L14",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/meta/ctstring.nr#L12-L14"})})})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Returns a new CtString with the given str appended onto the end."}),"\n",(0,s.jsx)(t.h3,{id:"append_fmtstr",children:"append_fmtstr"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",metastring:'title="append_fmtstr" showLineNumbers ',children:"pub comptime fn append_fmtstr<let N: u32, T>(self, s: fmtstr<N, T>) -> Self {\n"})}),"\n",(0,s.jsxs)(t.blockquote,{children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.sub,{children:(0,s.jsx)(t.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/meta/ctstring.nr#L18-L20",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/meta/ctstring.nr#L18-L20"})})})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Returns a new CtString with the given fmtstr appended onto the end."}),"\n",(0,s.jsx)(t.h3,{id:"as_quoted_str",children:"as_quoted_str"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",metastring:'title="as_quoted_str" showLineNumbers ',children:"pub comptime fn as_quoted_str(self) -> Quoted {\n"})}),"\n",(0,s.jsxs)(t.blockquote,{children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.sub,{children:(0,s.jsx)(t.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/meta/ctstring.nr#L27-L29",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/meta/ctstring.nr#L27-L29"})})})}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Returns a quoted string literal from this string's contents."}),"\n",(0,s.jsxs)(t.p,{children:["There is no direct conversion from a ",(0,s.jsx)(t.code,{children:"CtString"})," to a ",(0,s.jsx)(t.code,{children:"str<N>"})," since\nthe size would not be known. To get around this, this function can\nbe used in combination with macro insertion (",(0,s.jsx)(t.code,{children:"!"}),") to insert this string\nliteral at this function's call site."]}),"\n",(0,s.jsx)(t.p,{children:"Example:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",metastring:'title="as_quoted_str_example" showLineNumbers ',children:'let my_ctstring = "foo bar".as_ctstring();\nlet my_str: str<7> = my_ctstring.as_quoted_str!();\n\nassert_eq(crate::meta::type_of(my_str), quote { str<7> }.as_type());\n'})}),"\n",(0,s.jsxs)(t.blockquote,{children:["\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.sub,{children:(0,s.jsx)(t.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/meta/ctstring.nr#L83-L88",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/meta/ctstring.nr#L83-L88"})})})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"trait-implementations",children:"Trait Implementations"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-rust",children:"impl Eq for CtString\nimpl Hash for CtString\nimpl Append for CtString\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},28453(e,t,n){n.d(t,{R:()=>l,x:()=>a});var r=n(96540);const s={},i=r.createContext(s);function l(e){const t=r.useContext(i);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(i.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.