Some changes
This commit is contained in:
parent
a3058961f8
commit
d3bd38ba13
|
@ -47,17 +47,15 @@ impl IntoContext for Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chains another piece of context that is equal from a hierarchical perspective.
|
/// Chains another piece of context that is equal from a hierarchical perspective.
|
||||||
// TODO: should this inline? Would the compiler be allowed to fold the allocations into a
|
#[inline]
|
||||||
// single one with inlining?
|
|
||||||
fn chain(self, other: impl IntoContext) -> Self {
|
fn chain(self, other: impl IntoContext) -> Self {
|
||||||
let items = match self {
|
Context(ContextInner::Compound(match self {
|
||||||
Context(ContextInner::Compound(mut items)) => {
|
Context(ContextInner::Compound(mut items)) => {
|
||||||
items.push(other.into_context());
|
items.push(other.into_context());
|
||||||
items
|
items
|
||||||
}
|
}
|
||||||
_ => vec![self, other.into_context()],
|
_ => vec![self, other.into_context()],
|
||||||
};
|
}))
|
||||||
Context(ContextInner::Compound(items))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +74,7 @@ impl IntoContext for &'static str {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoContext for Cow<'static, str> {
|
impl IntoContext for Cow<'static, str> {
|
||||||
// TODO: should this always inline?
|
#[inline(always)]
|
||||||
#[inline]
|
|
||||||
fn into_context(self) -> Context {
|
fn into_context(self) -> Context {
|
||||||
Context(ContextInner::String(self))
|
Context(ContextInner::String(self))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![cfg_attr(feature = "backtrace", feature(backtrace))]
|
|
||||||
|
|
||||||
mod sealed;
|
mod sealed;
|
||||||
pub(crate) use sealed::seal;
|
pub(crate) use sealed::seal;
|
||||||
|
|
|
@ -25,6 +25,7 @@ impl ReportOpts {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn should_indent(&self) -> bool {
|
fn should_indent(&self) -> bool {
|
||||||
self.was_nl
|
self.was_nl
|
||||||
}
|
}
|
||||||
|
@ -37,6 +38,7 @@ macro_rules! report_write {
|
||||||
}
|
}
|
||||||
pub(crate) use report_write;
|
pub(crate) use report_write;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn write_indent(n: usize, f: &mut impl Write) -> std::fmt::Result {
|
fn write_indent(n: usize, f: &mut impl Write) -> std::fmt::Result {
|
||||||
for _ in 0..n {
|
for _ in 0..n {
|
||||||
f.write_str(" ")?;
|
f.write_str(" ")?;
|
||||||
|
@ -54,6 +56,7 @@ impl<T> Report for T
|
||||||
where
|
where
|
||||||
T: std::fmt::Display,
|
T: std::fmt::Display,
|
||||||
{
|
{
|
||||||
|
#[inline(never)]
|
||||||
fn fmt(&self, f: &mut impl Write, opts: &ReportOpts) -> std::fmt::Result {
|
fn fmt(&self, f: &mut impl Write, opts: &ReportOpts) -> std::fmt::Result {
|
||||||
use std::fmt::Error;
|
use std::fmt::Error;
|
||||||
struct IndentedWrite<'a, W: Write> {
|
struct IndentedWrite<'a, W: Write> {
|
||||||
|
@ -64,6 +67,7 @@ where
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||||
// TODO: any room for optimization?
|
// TODO: any room for optimization?
|
||||||
// iterates over the lines where each str ends with the line terminator.
|
// iterates over the lines where each str ends with the line terminator.
|
||||||
|
@ -84,6 +88,7 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn write_char(&mut self, c: char) -> Result<(), Error> {
|
fn write_char(&mut self, c: char) -> Result<(), Error> {
|
||||||
self.f.write_char(c)?;
|
self.f.write_char(c)?;
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub enum TerminationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Termination for TerminationResult {
|
impl Termination for TerminationResult {
|
||||||
|
#[inline]
|
||||||
fn report(self) -> ExitCode {
|
fn report(self) -> ExitCode {
|
||||||
match self {
|
match self {
|
||||||
Self::Ok => ExitCode::SUCCESS,
|
Self::Ok => ExitCode::SUCCESS,
|
||||||
|
@ -22,6 +23,7 @@ impl Termination for TerminationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Result<(), How>> for TerminationResult {
|
impl From<Result<(), How>> for TerminationResult {
|
||||||
|
#[inline]
|
||||||
fn from(value: Result<(), How>) -> Self {
|
fn from(value: Result<(), How>) -> Self {
|
||||||
match value {
|
match value {
|
||||||
Ok(()) => Self::Ok,
|
Ok(()) => Self::Ok,
|
||||||
|
|
Loading…
Reference in New Issue