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::Hashis 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 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 Nodes 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 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> 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>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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.