pub struct Parser { /* private fields */ }
Expand description
Configuration for parsing an input string as GraphQL syntax
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a Parser
with default configuration.
Use other methods to change the configuration.
Sourcepub fn recursion_limit(self, value: usize) -> Self
pub fn recursion_limit(self, value: usize) -> Self
Configure the recursion limit to use while parsing.
This protects against stack overflow.
If unset, use apollo-parser
’s default limit.
The exact meaning is unspecified,
but for GraphQL constructs like selection sets whose syntax can be nested,
the nesting level encountered during parsing counts towards this limit.
Sourcepub fn token_limit(self, value: usize) -> Self
pub fn token_limit(self, value: usize) -> Self
Configure the limit on the number of tokens to parse. If an input document is too big, parsing will be aborted. By default, there is no limit.
Sourcepub fn parse_ast(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<Document, WithErrors<Document>>
pub fn parse_ast( &mut self, source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<Document, WithErrors<Document>>
Parse the given source text into an AST document.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Sourcepub fn parse_schema(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<Schema, WithErrors<Schema>>
pub fn parse_schema( &mut self, source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<Schema, WithErrors<Schema>>
Parse the given source text as the sole input file of a schema.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
To have multiple files contribute to a schema,
use Schema::builder
and Parser::parse_into_schema_builder
.
Sourcepub fn parse_into_schema_builder(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>,
builder: &mut SchemaBuilder,
)
pub fn parse_into_schema_builder( &mut self, source_text: impl Into<String>, path: impl AsRef<Path>, builder: &mut SchemaBuilder, )
Parse the given source text as an additional input to a schema builder.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
This can be used to build a schema from multiple source files.
Errors (if any) are recorded in the builder and returned by SchemaBuilder::build
.
Sourcepub fn parse_executable(
&mut self,
schema: &Valid<Schema>,
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<ExecutableDocument, WithErrors<ExecutableDocument>>
pub fn parse_executable( &mut self, schema: &Valid<Schema>, source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<ExecutableDocument, WithErrors<ExecutableDocument>>
Parse the given source text into an executable document, with the given schema.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Sourcepub fn parse_mixed_validate(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<(Valid<Schema>, Valid<ExecutableDocument>), DiagnosticList>
pub fn parse_mixed_validate( &mut self, source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<(Valid<Schema>, Valid<ExecutableDocument>), DiagnosticList>
Parse a schema and executable document from the given source text containing a mixture of type system definitions and executable definitions, and validate them. This is mostly useful for unit tests.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Sourcepub fn parse_field_set(
&mut self,
schema: &Valid<Schema>,
type_name: NamedType,
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<FieldSet, WithErrors<FieldSet>>
pub fn parse_field_set( &mut self, schema: &Valid<Schema>, type_name: NamedType, source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<FieldSet, WithErrors<FieldSet>>
Parse the given source text (e.g. field_1 field_2 { field_2_1 }
as a selection set with optional outer brackets.
This is the syntax of the string argument to some Apollo Federation directives.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Sourcepub fn parse_type(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>,
) -> Result<Type, DiagnosticList>
pub fn parse_type( &mut self, source_text: impl Into<String>, path: impl AsRef<Path>, ) -> Result<Type, DiagnosticList>
Parse the given source text (e.g. [Foo!]!
) as a reference to a GraphQL type.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Sourcepub fn recursion_reached(&self) -> usize
pub fn recursion_reached(&self) -> usize
What level of recursion was reached during the last call to a parse_*
method.
Collecting this on a corpus of documents can help decide
how to set recursion_limit
.
Sourcepub fn tokens_reached(&self) -> usize
pub fn tokens_reached(&self) -> usize
How many tokens were created during the last call to a parse_*
method.
Collecting this on a corpus of documents can help decide
how to set token_limit
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnwindSafe for Parser
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<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);