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 optional NodeLocation. This location notably allows diagnostics to point to relevant parts of parsed input files.
  • std::hash::Hash is implemented by caching the result of hashing T.
  • 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>

source

pub fn new_parsed(node: T, location: NodeLocation) -> Self

Create a new Node for something parsed from the given source location

source

pub fn new(node: T) -> Self

Create a new Node for something created programatically, not parsed from a source file

source

pub fn location(&self) -> Option<NodeLocation>

source

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.

source

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).

source

pub fn to_component(&self, origin: ComponentOrigin) -> Component<T>

source

pub fn ptr_eq(&self, other: &Self) -> bool

Returns whether two Nodes point to the same memory allocation

source

pub fn make_mut(&mut self) -> &mut T
where 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.

source

pub fn get_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to T if this Node is uniquely owned

Trait Implementations§

source§

impl<T> AsRef<T> for Node<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Clone for Node<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Node<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for Node<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Deref for Node<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: Display> Display for Node<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&String> for Node<Value>

source§

fn from(value: &String) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Node<Value>

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<()> for Node<Value>

source§

fn from(value: ()) -> Self

Converts to this type from the input type.
source§

impl<N: Into<Name>, V: Into<Node<Value>>> From<(N, V)> for Node<Argument>

source§

fn from((name, value): (N, V)) -> Self

Converts to this type from the input type.
source§

impl From<Node<DirectiveDefinition>> for Definition

source§

fn from(def: Node<DirectiveDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<EnumType>> for ExtendedType

source§

fn from(ty: Node<EnumType>) -> Self

Converts to this type from the input type.
source§

impl From<Node<EnumTypeDefinition>> for Definition

source§

fn from(def: Node<EnumTypeDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<EnumTypeExtension>> for Definition

source§

fn from(def: Node<EnumTypeExtension>) -> Self

Converts to this type from the input type.
source§

impl From<Node<Field>> for Selection

source§

fn from(node: Node<Field>) -> Self

Converts to this type from the input type.
source§

impl From<Node<FragmentDefinition>> for Definition

source§

fn from(def: Node<FragmentDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<FragmentSpread>> for Selection

source§

fn from(node: Node<FragmentSpread>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InlineFragment>> for Selection

source§

fn from(node: Node<InlineFragment>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InputObjectType>> for ExtendedType

source§

fn from(ty: Node<InputObjectType>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InputObjectTypeDefinition>> for Definition

source§

fn from(def: Node<InputObjectTypeDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InputObjectTypeExtension>> for Definition

source§

fn from(def: Node<InputObjectTypeExtension>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InterfaceType>> for ExtendedType

source§

fn from(ty: Node<InterfaceType>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InterfaceTypeDefinition>> for Definition

source§

fn from(def: Node<InterfaceTypeDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<InterfaceTypeExtension>> for Definition

source§

fn from(def: Node<InterfaceTypeExtension>) -> Self

Converts to this type from the input type.
source§

impl From<Node<ObjectType>> for ExtendedType

source§

fn from(ty: Node<ObjectType>) -> Self

Converts to this type from the input type.
source§

impl From<Node<ObjectTypeDefinition>> for Definition

source§

fn from(def: Node<ObjectTypeDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<ObjectTypeExtension>> for Definition

source§

fn from(def: Node<ObjectTypeExtension>) -> Self

Converts to this type from the input type.
source§

impl From<Node<OperationDefinition>> for Definition

source§

fn from(def: Node<OperationDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<ScalarType>> for ExtendedType

source§

fn from(ty: Node<ScalarType>) -> Self

Converts to this type from the input type.
source§

impl From<Node<ScalarTypeDefinition>> for Definition

source§

fn from(def: Node<ScalarTypeDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<ScalarTypeExtension>> for Definition

source§

fn from(def: Node<ScalarTypeExtension>) -> Self

Converts to this type from the input type.
source§

impl From<Node<SchemaDefinition>> for Definition

source§

fn from(def: Node<SchemaDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<SchemaExtension>> for Definition

source§

fn from(def: Node<SchemaExtension>) -> Self

Converts to this type from the input type.
source§

impl From<Node<UnionType>> for ExtendedType

source§

fn from(ty: Node<UnionType>) -> Self

Converts to this type from the input type.
source§

impl From<Node<UnionTypeDefinition>> for Definition

source§

fn from(def: Node<UnionTypeDefinition>) -> Self

Converts to this type from the input type.
source§

impl From<Node<UnionTypeExtension>> for Definition

source§

fn from(def: Node<UnionTypeExtension>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Node<Value>

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Node<T>

source§

fn from(node: T) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Node<Value>

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Node<Value>

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Node<Value>

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Node<T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: PartialEq> PartialEq for Node<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for Node<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Node<T>
where T: RefUnwindSafe,

§

impl<T> Send for Node<T>
where T: Send + Sync,

§

impl<T> Sync for Node<T>
where T: Send + Sync,

§

impl<T> Unpin for Node<T>
where T: Unpin,

§

impl<T> UnwindSafe for Node<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> Fmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromFd for T
where T: From<OwnedFd>,

§

fn from_fd(owned_fd: OwnedFd) -> T

👎Deprecated since 1.0.0: FromFd::from_fd is replaced by From<OwnedFd>::from
Constructs a new instance of Self from the given file descriptor. Read more
§

fn from_into_fd<Owned>(into_owned: Owned) -> Self
where Owned: Into<OwnedFd>, Self: Sized + From<OwnedFd>,

Constructs a new instance of Self from the given file descriptor converted from into_owned. Read more
§

impl<T> FromFilelike for T
where T: From<OwnedFd>,

§

fn from_filelike(owned: OwnedFd) -> T

Constructs a new instance of Self from the given filelike object. Read more
§

fn from_into_filelike<Owned>(owned: Owned) -> T
where Owned: IntoFilelike,

Constructs a new instance of Self from the given filelike object converted from into_owned. Read more
§

impl<T> FromSocketlike for T
where T: From<OwnedFd>,

§

fn from_socketlike(owned: OwnedFd) -> T

Constructs a new instance of Self from the given socketlike object.
§

fn from_into_socketlike<Owned>(owned: Owned) -> T
where Owned: IntoSocketlike,

Constructs a new instance of Self from the given socketlike object converted from into_owned.
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StdoutFmt for T
where T: Display,

source§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>,

Give this value the specified foreground colour, when color is enabled for stdout.
source§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>,

Give this value the specified background colour, when color is enabled for stdout.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.