Struct apollo_compiler::Node
source · pub struct Node<T>(/* 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 optionalNodeLocation
. This location notably allows diagnostics to point to relevant parts of parsed input files. std::hash::Hash
is implemented by caching the result of hashingT
.- Weak references are not supported.
For the cache to be correct, T
is expected to have a stable hash
a long as no &mut T
exclusive reference to it is given out.
Generally this excludes interior mutability.
Node<T>
cannot implement Borrow<T>
because Node<T> as Hash
produces a result (the hash of the cached hash) different from T as Hash
.
Implementations§
source§impl<T> Node<T>
impl<T> Node<T>
sourcepub fn new_parsed(node: T, location: NodeLocation) -> Self
pub fn new_parsed(node: T, location: NodeLocation) -> Self
Create a new Node
for something parsed from the given source location
sourcepub fn new(node: T) -> Self
pub fn new(node: T) -> Self
Create a new Node
for something created programatically, not parsed from a source file
pub fn location(&self) -> Option<NodeLocation>
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(&self, sources: &SourceMap) -> Option<GraphQLLocation>
pub fn line_column(&self, sources: &SourceMap) -> Option<GraphQLLocation>
If this node contains a location, convert it to 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>,
impl<'de, T> Deserialize<'de> for Node<T>where
T: Deserialize<'de>,
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
source§impl<T: PartialEq> PartialEq for Node<T>
impl<T: PartialEq> PartialEq for Node<T>
impl<T: Eq> Eq for Node<T>
Auto Trait Implementations§
impl<T> Freeze for Node<T>
impl<T> RefUnwindSafe for Node<T>where
T: RefUnwindSafe,
impl<T> Send for Node<T>
impl<T> Sync for Node<T>
impl<T> Unpin for Node<T>where
T: Unpin,
impl<T> UnwindSafe for Node<T>where
T: UnwindSafe + RefUnwindSafe,
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<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>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
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>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.bright_yellow());
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>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.bright_magenta());
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>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
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>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
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>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.on_bright_yellow());
source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
§Example
println!("{}", value.on_bright_blue());
source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.on_bright_magenta());
source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
§Example
println!("{}", value.on_bright_cyan());
source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.on_bright_white());
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 underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
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);