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 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 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<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>
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§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 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.§impl<T> FromFd for T
impl<T> FromFd for T
§impl<T> FromFilelike for T
impl<T> FromFilelike for T
§fn from_filelike(owned: OwnedFd) -> T
fn from_filelike(owned: OwnedFd) -> T
Self
from the given filelike object. Read more§fn from_into_filelike<Owned>(owned: Owned) -> Twhere
Owned: IntoFilelike,
fn from_into_filelike<Owned>(owned: Owned) -> Twhere
Owned: IntoFilelike,
Self
from the given filelike object
converted from into_owned
. Read more§impl<T> FromSocketlike for T
impl<T> FromSocketlike for T
§fn from_socketlike(owned: OwnedFd) -> T
fn from_socketlike(owned: OwnedFd) -> T
Self
from the given socketlike object.§fn from_into_socketlike<Owned>(owned: Owned) -> Twhere
Owned: IntoSocketlike,
fn from_into_socketlike<Owned>(owned: Owned) -> Twhere
Owned: IntoSocketlike,
Self
from the given socketlike object
converted from into_owned
.