rust-analyzer/syntax/ast/trait.AstNode.html

30 lines
93 KiB
HTML
Raw Normal View History

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The main trait to go from untyped `SyntaxNode` to a typed ast. The conversion itself has zero runtime cost: ast and syntax nodes have exactly the same representation: a pointer to the tree root and a pointer to the node itself."><title>AstNode in syntax::ast - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="syntax" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../syntax/index.html">syntax</a><span class="version">0.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">AstNode</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.can_cast" title="can_cast">can_cast</a></li><li><a href="#tymethod.cast" title="cast">cast</a></li><li><a href="#tymethod.syntax" title="syntax">syntax</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.clone_for_update" title="clone_for_update">clone_for_update</a></li><li><a href="#method.clone_subtree" title="clone_subtree">clone_subtree</a></li><li><a href="#method.kind" title="kind">kind</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-AstNode-for-Either%3CL,+R%3E" title="Either&#60;L, R&#62;">Either&#60;L, R&#62;</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In syntax::<wbr>ast</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">syntax</a>::<wbr><a href="index.html">ast</a></span><h1>Trait <span class="trait">AstNode</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/syntax/ast.rs.html#44-74">Source</a> </span></div><pre class="rust item-decl"><code>pub trait AstNode {
// Required methods
fn <a href="#tymethod.can_cast" class="fn">can_cast</a>(kind: <a class="enum" href="../enum.SyntaxKind.html" title="enum syntax::SyntaxKind">SyntaxKind</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a>
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.cast" class="fn">cast</a>(syntax: <a class="type" href="../type.SyntaxNode.html" title="type syntax::SyntaxNode">SyntaxNode</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;Self&gt;
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;
<span class="item-spacer"></span> fn <a href="#tymethod.syntax" class="fn">syntax</a>(&amp;self) -&gt; &amp;<a class="type" href="../type.SyntaxNode.html" title="type syntax::SyntaxNode">SyntaxNode</a>;
// Provided methods
fn <a href="#method.kind" class="fn">kind</a>() -&gt; <a class="enum" href="../enum.SyntaxKind.html" title="enum syntax::SyntaxKind">SyntaxKind</a>
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
<span class="item-spacer"></span> fn <a href="#method.clone_for_update" class="fn">clone_for_update</a>(&amp;self) -&gt; Self
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
<span class="item-spacer"></span> fn <a href="#method.clone_subtree" class="fn">clone_subtree</a>(&amp;self) -&gt; Self
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The main trait to go from untyped <code>SyntaxNode</code> to a typed ast. The
conversion itself has zero runtime cost: ast and syntax nodes have exactly
the same representation: a pointer to the tree root and a pointer to the
node itself.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><section id="tymethod.can_cast" class="method"><a class="src rightside" href="../../src/syntax/ast.rs.html#53-55">Source</a><h4 class="code-header">fn <a href="#tymethod.can_cast" class="fn">can_cast</a>(kind: <a class="enum" href="../enum.SyntaxKind.html" title="enum syntax::SyntaxKind">SyntaxKind</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a><div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="tymethod.cast" class="method"><a class="src rightside" href="../../src/syntax/ast.rs.html#57-59">Source</a><h4 class="code-header">fn <a href="#tymethod.cast" class="fn">cast</a>(syntax: <a class="type" href="../type.SyntaxNode.html" title="type syntax::SyntaxNode">SyntaxNode</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;Self&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="tymethod.syntax" class="method"><a class="src rightside" href="../../src/syntax/ast.rs.html#61">Source</a><h4 class="code-header">fn <a href="#tymethod.syntax" class="fn">syntax</a>(&amp;self) -&gt; &amp;<a class="type" href="../type.SyntaxNode.html" title="type syntax::SyntaxNode">SyntaxNode</a></h4></section></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.kind" class="method"><a class="src rightside" href="../../src/syntax/ast.rs.html#46-51">Source</a><h4 class="code-header">fn <a href="#method.kind" class="fn">kind</a>() -&gt; <a class="enum" href="../enum.SyntaxKind.html" title="enum syntax::SyntaxKind">SyntaxKind</a><div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>This panics if the <code>SyntaxKind</code> is not statically known.</p>
</div></details><section id="method.clone_for_update" class="method"><a class="src rightside" href="../../src/syntax/ast.rs.html#62-67">Source</a><h4 class="code-header">fn <a href="#method.clone_for_update" class="fn">clone_for_update</a>(&amp;self) -&gt; Self<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.clone_subtree" class="method"><a class="src rightside" href="../../src/syntax/ast.rs.html#68-73">Source</a><h4 class="code-header">fn <a href="#method.clone_subtree" class="fn">clone_subtree</a>(&amp;self) -&gt; Self<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-AstNode-for-Either%3CL,+R%3E" class="impl"><a class="src rightside" href="../../src/syntax/ast.rs.html#113-139">Source</a><a href="#impl-AstNode-for-Either%3CL,+R%3E" class="anchor">§</a><h3 class="code-header">impl&lt;L, R&gt; <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either">Either</a>&lt;L, R&gt;<div class="where">where
L: <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a>,
R: <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a>,</div></h3></section></summary><div class="impl-items"><section id="method.can_cast" class="method trait-impl"><a class="src rightside" href="../../src/syntax/ast.rs.html#118-123">Source</a><a href="#method.can_cast" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.can_cast" class="fn">can_cast</a>(kind: <a class="enum" href="../enum.SyntaxKind.html" title="enum syntax::SyntaxKind">SyntaxKind</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a><div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.cast" class="method trait-impl"><a class="src rightside" href="../../src/syntax/ast.rs.html#125-134">Source</a><a href="#method.cast" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.cast" class="fn">cast</a>(syntax: <a class="type" href="../type.SyntaxNode.html" title="type syntax::SyntaxNode">SyntaxNode</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;Self&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section><section id="method.syntax" class="method trait-impl"><a class="src rightside" href="../../src/syntax/ast.rs.html#136-138">Source</a><a href="#method.syntax" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.syntax" class="fn">syntax</a>(&amp;self) -&gt; &amp;<a class="type" href="../type.SyntaxNode.html" title="type syntax::SyntaxNode">SyntaxNode</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-AstNode-for-Adt" class="impl"><a class="src rightside" href="../../src/syntax/ast/generated/nodes.rs.html#5750-5771">Source</a><a href="#impl-AstNode-for-Adt" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.Adt.html" title="enum syntax::ast::Adt">Adt</a></h3></section><section id="impl-AstNode-for-AsmOperand" class="impl"><a class="src rightside" href="../../src/syntax/ast/generated/nodes.rs.html#5788-5813">Source</a><a href="#impl-AstNode-for-AsmOperand" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.AsmOperand.html" title="enum syntax::ast::AsmOperand">AsmOperand</a></h3></section><section id="impl-AstNode-for-AsmPiece" class="impl"><a class="src rightside" href="../../src/syntax/ast/generated/nodes.rs.html#5826-5849">Source</a><a href="#impl-AstNode-for-AsmPiece" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.AsmPiece.html" title="enum syntax::ast::AsmPiece">AsmPiece</a></h3></section><section id="impl-AstNode-for-AssocItem" class="impl"><a class="src rightside" href="../../src/syntax/ast/generated/nodes.rs.html#5866-5889">Source</a><a href="#impl-AstNode-for-AssocItem" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.AssocItem.html" title="enum syntax::ast::AssocItem">AssocItem</a></h3></section><section id="impl-AstNode-for-CallableExpr" class="impl"><a class="src rightside" href="../../src/syntax/ast/expr_ext.rs.html#447-472">Source</a><a href="#impl-AstNode-for-CallableExpr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.CallableExpr.html" title="enum syntax::ast::CallableExpr">CallableExpr</a></h3></section><section id="impl-AstNode-for-ElseBranch" class="impl"><a class="src rightside" href="../../src/syntax/ast/expr_ext.rs.html#53-72">Source</a><a href="#impl-AstNode-for-ElseBranch" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.ElseBranch.html" title="enum syntax::ast::ElseBranch">ElseBranch</a></h3></section><section id="impl-AstNode-for-Expr" class="impl"><a class="src rightside" href="../../src/syntax/ast/generated/nodes.rs.html#6034-6161">Source</a><a href="#impl-AstNode-for-Expr" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.Expr.html" title="enum syntax::ast::Expr">Expr</a></h3></section><section id="impl-AstNode-for-ExternItem" class="impl"><a class="src rightside" href="../../src/syntax/ast/generated/nodes.rs.html#6178-6201">Source</a><a href="#impl-AstNode-for-ExternItem" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AstNode.html" title="trait syntax::ast::AstNode">AstNode</a> for <a class="enum" href="enum.ExternItem.