pub struct Node<T: ?Sized>(/* private fields */);
Expand description
A thread-safe reference-counted smart pointer for GraphQL nodes.
Similar to std::sync::Arc<T>
but:
- In addition to
T
, contains an optionalSourceSpan
. This location notably allows diagnostics to point to relevant parts of parsed input files. - Weak references are not supported.
Implementations§
Source§impl<T> Node<T>
impl<T> Node<T>
Sourcepub fn new_parsed(node: T, location: SourceSpan) -> Self
pub fn new_parsed(node: T, location: SourceSpan) -> Self
Create a new Node
for something parsed from the given source location
Source§impl Node<str>
impl Node<str>
Sourcepub fn new_str_parsed(node: &str, location: SourceSpan) -> Self
pub fn new_str_parsed(node: &str, location: SourceSpan) -> Self
Create a new Node<str>
for a string parsed from the given source location
Sourcepub fn new_str(node: &str) -> Self
pub fn new_str(node: &str) -> Self
Create a new Node<str>
for a string created programatically, not parsed from a source file
pub fn as_str(&self) -> &str
Source§impl<T: ?Sized> Node<T>
impl<T: ?Sized> Node<T>
Sourcepub fn location(&self) -> Option<SourceSpan>
pub fn location(&self) -> Option<SourceSpan>
If this node was parsed from a source file, returns the file ID and source span (start and end byte offsets) within that file.
Sourcepub fn is_built_in(&self) -> bool
pub fn is_built_in(&self) -> bool
Whether this node is located in FileId::BUILT_IN
,
which defines built-in directives, built-in scalars, and introspection types.
Sourcepub fn line_column_range(
&self,
sources: &SourceMap,
) -> Option<Range<LineColumn>>
pub fn line_column_range( &self, sources: &SourceMap, ) -> Option<Range<LineColumn>>
If this node contains a location, convert it to the line and column numbers.
Sourcepub fn same_location<U>(&self, node: U) -> Node<U>
pub fn same_location<U>(&self, node: U) -> Node<U>
Returns the given node
at the same location as self
(e.g. for a type conversion).
pub fn to_component(&self, origin: ComponentOrigin) -> Component<T>
Sourcepub fn ptr_eq(&self, other: &Self) -> bool
pub fn ptr_eq(&self, other: &Self) -> bool
Returns whether two Node
s point to the same memory allocation
Sourcepub fn make_mut(&mut self) -> &mut Twhere
T: Clone,
pub fn make_mut(&mut self) -> &mut Twhere
T: Clone,
Returns a mutable reference to T
, cloning it if necessary
This is functionally equivalent to Arc::make_mut
from the standard library.
If this Node
is uniquely owned, make_mut()
will provide a mutable
reference to the contents. If not, make_mut()
will create a new Node
with a clone of the contents, update self
to point to it, and provide
a mutable reference to its contents.
This is useful for implementing copy-on-write schemes where you wish to
avoid copying things if your Node
is not shared.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Node<T>where
T: Deserialize<'de> + ?Sized,
impl<'de, T> Deserialize<'de> for Node<T>where
T: Deserialize<'de> + ?Sized,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'schema> From<&'schema Node<DirectiveDefinition>> for SchemaCoordinateLookup<'schema>
impl<'schema> From<&'schema Node<DirectiveDefinition>> for SchemaCoordinateLookup<'schema>
Source§fn from(inner: &'schema Node<DirectiveDefinition>) -> Self
fn from(inner: &'schema Node<DirectiveDefinition>) -> Self
Source§impl<'schema> From<&'schema Node<InputValueDefinition>> for SchemaCoordinateLookup<'schema>
impl<'schema> From<&'schema Node<InputValueDefinition>> for SchemaCoordinateLookup<'schema>
Source§fn from(inner: &'schema Node<InputValueDefinition>) -> Self
fn from(inner: &'schema Node<InputValueDefinition>) -> Self
Source§impl From<Node<DirectiveDefinition>> for Definition
impl From<Node<DirectiveDefinition>> for Definition
Source§fn from(def: Node<DirectiveDefinition>) -> Self
fn from(def: Node<DirectiveDefinition>) -> Self
Source§impl From<Node<EnumTypeDefinition>> for Definition
impl From<Node<EnumTypeDefinition>> for Definition
Source§fn from(def: Node<EnumTypeDefinition>) -> Self
fn from(def: Node<EnumTypeDefinition>) -> Self
Source§impl From<Node<EnumTypeExtension>> for Definition
impl From<Node<EnumTypeExtension>> for Definition
Source§fn from(def: Node<EnumTypeExtension>) -> Self
fn from(def: Node<EnumTypeExtension>) -> Self
Source§impl From<Node<FragmentDefinition>> for Definition
impl From<Node<FragmentDefinition>> for Definition
Source§fn from(def: Node<FragmentDefinition>) -> Self
fn from(def: Node<FragmentDefinition>) -> Self
Source§impl From<Node<FragmentSpread>> for Selection
impl From<Node<FragmentSpread>> for Selection
Source§fn from(node: Node<FragmentSpread>) -> Self
fn from(node: Node<FragmentSpread>) -> Self
Source§impl From<Node<InlineFragment>> for Selection
impl From<Node<InlineFragment>> for Selection
Source§fn from(node: Node<InlineFragment>) -> Self
fn from(node: Node<InlineFragment>) -> Self
Source§impl From<Node<InputObjectType>> for ExtendedType
impl From<Node<InputObjectType>> for ExtendedType
Source§fn from(ty: Node<InputObjectType>) -> Self
fn from(ty: Node<InputObjectType>) -> Self
Source§impl From<Node<InputObjectTypeDefinition>> for Definition
impl From<Node<InputObjectTypeDefinition>> for Definition
Source§fn from(def: Node<InputObjectTypeDefinition>) -> Self
fn from(def: Node<InputObjectTypeDefinition>) -> Self
Source§impl From<Node<InputObjectTypeExtension>> for Definition
impl From<Node<InputObjectTypeExtension>> for Definition
Source§fn from(def: Node<InputObjectTypeExtension>) -> Self
fn from(def: Node<InputObjectTypeExtension>) -> Self
Source§impl From<Node<InterfaceType>> for ExtendedType
impl From<Node<InterfaceType>> for ExtendedType
Source§fn from(ty: Node<InterfaceType>) -> Self
fn from(ty: Node<InterfaceType>) -> Self
Source§impl From<Node<InterfaceTypeDefinition>> for Definition
impl From<Node<InterfaceTypeDefinition>> for Definition
Source§fn from(def: Node<InterfaceTypeDefinition>) -> Self
fn from(def: Node<InterfaceTypeDefinition>) -> Self
Source§impl From<Node<InterfaceTypeExtension>> for Definition
impl From<Node<InterfaceTypeExtension>> for Definition
Source§fn from(def: Node<InterfaceTypeExtension>) -> Self
fn from(def: Node<InterfaceTypeExtension>) -> Self
Source§impl From<Node<ObjectType>> for ExtendedType
impl From<Node<ObjectType>> for ExtendedType
Source§fn from(ty: Node<ObjectType>) -> Self
fn from(ty: Node<ObjectType>) -> Self
Source§impl From<Node<ObjectTypeDefinition>> for Definition
impl From<Node<ObjectTypeDefinition>> for Definition
Source§fn from(def: Node<ObjectTypeDefinition>) -> Self
fn from(def: Node<ObjectTypeDefinition>) -> Self
Source§impl From<Node<ObjectTypeExtension>> for Definition
impl From<Node<ObjectTypeExtension>> for Definition
Source§fn from(def: Node<ObjectTypeExtension>) -> Self
fn from(def: Node<ObjectTypeExtension>) -> Self
Source§impl From<Node<OperationDefinition>> for Definition
impl From<Node<OperationDefinition>> for Definition
Source§fn from(def: Node<OperationDefinition>) -> Self
fn from(def: Node<OperationDefinition>) -> Self
Source§impl From<Node<ScalarType>> for ExtendedType
impl From<Node<ScalarType>> for ExtendedType
Source§fn from(ty: Node<ScalarType>) -> Self
fn from(ty: Node<ScalarType>) -> Self
Source§impl From<Node<ScalarTypeDefinition>> for Definition
impl From<Node<ScalarTypeDefinition>> for Definition
Source§fn from(def: Node<ScalarTypeDefinition>) -> Self
fn from(def: Node<ScalarTypeDefinition>) -> Self
Source§impl From<Node<ScalarTypeExtension>> for Definition
impl From<Node<ScalarTypeExtension>> for Definition
Source§fn from(def: Node<ScalarTypeExtension>) -> Self
fn from(def: Node<ScalarTypeExtension>) -> Self
Source§impl From<Node<SchemaDefinition>> for Definition
impl From<Node<SchemaDefinition>> for Definition
Source§fn from(def: Node<SchemaDefinition>) -> Self
fn from(def: Node<SchemaDefinition>) -> Self
Source§impl From<Node<SchemaExtension>> for Definition
impl From<Node<SchemaExtension>> for Definition
Source§fn from(def: Node<SchemaExtension>) -> Self
fn from(def: Node<SchemaExtension>) -> Self
Source§impl From<Node<UnionTypeDefinition>> for Definition
impl From<Node<UnionTypeDefinition>> for Definition
Source§fn from(def: Node<UnionTypeDefinition>) -> Self
fn from(def: Node<UnionTypeDefinition>) -> Self
Source§impl From<Node<UnionTypeExtension>> for Definition
impl From<Node<UnionTypeExtension>> for Definition
Source§fn from(def: Node<UnionTypeExtension>) -> Self
fn from(def: Node<UnionTypeExtension>) -> Self
Source§impl FromIterator<Node<Directive>> for DirectiveList
impl FromIterator<Node<Directive>> for DirectiveList
impl<T: ?Sized + Eq> Eq for Node<T>
Auto Trait Implementations§
impl<T> Freeze for Node<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Node<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for Node<T>
impl<T> Sync for Node<T>
impl<T> Unpin for Node<T>
impl<T> UnwindSafe for Node<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);