pub struct Signature<PT: ProtocolTypes> {
pub functions_by_name: HashMap<&'static str, FunctionDefinition<PT>>,
pub functions_by_typ: HashMap<TypeShape<PT>, Vec<FunctionDefinition<PT>>>,
pub functions: Vec<FunctionDefinition<PT>>,
pub types_by_name: HashMap<&'static str, TypeShape<PT>>,
pub attrs_by_name: HashMap<&'static str, FunctionAttributes>,
min_cost_by_name: HashMap<&'static str, Cost>,
min_cost_by_typ: HashMap<TypeShape<PT>, Cost>,
functions_by_typ_by_depth: HashMap<TypeShape<PT>, DepthOrdered<PT>>,
}Expand description
Records a universe of functions. Signatures are containers for types and function symbols. They hold references to the concrete implementations of functions and the types of variables.
Fields§
§functions_by_name: HashMap<&'static str, FunctionDefinition<PT>>§functions_by_typ: HashMap<TypeShape<PT>, Vec<FunctionDefinition<PT>>>§functions: Vec<FunctionDefinition<PT>>§types_by_name: HashMap<&'static str, TypeShape<PT>>§attrs_by_name: HashMap<&'static str, FunctionAttributes>§min_cost_by_name: HashMap<&'static str, Cost>Minimal generation depth and size per function symbol, see Self::min_gen_depth and
Self::min_gen_size.
min_cost_by_typ: HashMap<TypeShape<PT>, Cost>Minimal generation depth and size per type, see Self::min_gen_depth_of_type and
Self::min_gen_size_of_type.
functions_by_typ_by_depth: HashMap<TypeShape<PT>, DepthOrdered<PT>>Per type, the symbols returning it, ordered by increasing minimal depth, see
Self::choose_function_within.
Implementations§
Source§impl<PT: ProtocolTypes> Signature<PT>
impl<PT: ProtocolTypes> Signature<PT>
Sourcepub fn new(
definitions: Vec<(FunctionDefinition<PT>, FunctionAttributes)>,
) -> Self
pub fn new( definitions: Vec<(FunctionDefinition<PT>, FunctionAttributes)>, ) -> Self
Construct a Signature from the given FunctionDefinitions.
Sourcefn compute_min_costs(
definitions: &[(FunctionDefinition<PT>, FunctionAttributes)],
) -> (HashMap<&'static str, Cost>, HashMap<TypeShape<PT>, Cost>)
fn compute_min_costs( definitions: &[(FunctionDefinition<PT>, FunctionAttributes)], ) -> (HashMap<&'static str, Cost>, HashMap<TypeShape<PT>, Cost>)
Least fixed point of
depth(f) = 1 + max { depth(t) | t argument type of f }(so1for a constant),size(f) = 1 + sum { size(t) | t argument type of f }(so1for a constant),cost(t) = the pointwise min over the symbols returning t.
Symbols with an argument type no function can build, and the types only such symbols return, are absent from the returned maps: no closed term exists for them at any cost.
Sourcepub fn min_gen_depth(&self, name: &str) -> Option<u16>
pub fn min_gen_depth(&self, name: &str) -> Option<u16>
The minimal depth at which the term zoo can build a closed term rooted at name: 1 for a
constant, 1 + max over the argument types otherwise. Matches the budget accounting of
crate::fuzzer::term_zoo, so a generation attempt for name with a budget below this can
only fail.
None when no closed term is rooted at name at any depth (some argument type has no
closed term), which also means name is unknown to this signature.
Sourcepub fn min_gen_size(&self, name: &str) -> Option<usize>
pub fn min_gen_size(&self, name: &str) -> Option<usize>
The size, in nodes, of the smallest closed term rooted at name: 1 for a constant,
1 + sum over the argument types otherwise. Same conventions as Self::min_gen_depth.
Sourcepub fn min_gen_depth_of_type(&self, typ: &TypeShape<PT>) -> Option<u16>
pub fn min_gen_depth_of_type(&self, typ: &TypeShape<PT>) -> Option<u16>
Same as Self::min_gen_depth, for the shallowest closed term of the given type.
Sourcepub fn min_gen_size_of_type(&self, typ: &TypeShape<PT>) -> Option<usize>
pub fn min_gen_size_of_type(&self, typ: &TypeShape<PT>) -> Option<usize>
Same as Self::min_gen_size, for the smallest closed term of the given type.
Note this is a lower bound rather than an achievable cost: the shallowest and the smallest term of a type need not be the same one, and the two components are minimised separately.
Sourcepub fn choose_function_within<R: Rand>(
&self,
typ: &TypeShape<PT>,
depth: u16,
size: usize,
rand: &mut R,
) -> Option<&FunctionDefinition<PT>>
pub fn choose_function_within<R: Rand>( &self, typ: &TypeShape<PT>, depth: u16, size: usize, rand: &mut R, ) -> Option<&FunctionDefinition<PT>>
Uniformly picks a symbol of the given type that the term zoo can build a closed term for
within depth levels and size nodes.
None when the type is unknown or when no symbol of that type is that cheap.
Sourcepub fn new_function<F: 'static + DescribableFunction<PT, Types>, Types>(
f: &'static F,
) -> Function<PT>
pub fn new_function<F: 'static + DescribableFunction<PT, Types>, Types>( f: &'static F, ) -> Function<PT>
pub fn new_var_with_type<T: 'static, M: Matcher>(
source: Option<Source>,
matcher: Option<M>,
counter: u16,
) -> Variable<PT>where
PT: ProtocolTypes<Matcher = M>,
pub fn new_var<M: Matcher>(
type_shape: TypeShape<PT>,
source: Option<Source>,
matcher: Option<M>,
counter: u16,
) -> Variable<PT>where
PT: ProtocolTypes<Matcher = M>,
Trait Implementations§
Auto Trait Implementations§
impl<PT> Freeze for Signature<PT>
impl<PT> !RefUnwindSafe for Signature<PT>
impl<PT> Send for Signature<PT>where
PT: Send,
impl<PT> Sync for Signature<PT>where
PT: Sync,
impl<PT> Unpin for Signature<PT>where
PT: Unpin,
impl<PT> !UnwindSafe for Signature<PT>
Blanket Implementations§
§impl<Head, T> Append<T> for Head
impl<Head, T> Append<T> for Head
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<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§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();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§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();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§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();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§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();§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.§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);