mirror of
https://github.com/typst/typst
synced 2025-06-22 21:32:52 +08:00
Add typst_utils::display
This commit is contained in:
parent
4580daf307
commit
15302dbe7a
@ -23,7 +23,7 @@ pub use self::scalar::Scalar;
|
||||
#[doc(hidden)]
|
||||
pub use once_cell;
|
||||
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::hash::Hash;
|
||||
use std::iter::{Chain, Flatten, Rev};
|
||||
use std::num::{NonZeroU32, NonZeroUsize};
|
||||
@ -52,6 +52,25 @@ where
|
||||
Wrapper(f)
|
||||
}
|
||||
|
||||
/// Turn a closure into a struct implementing [`Display`].
|
||||
pub fn display<F>(f: F) -> impl Display
|
||||
where
|
||||
F: Fn(&mut Formatter) -> std::fmt::Result,
|
||||
{
|
||||
struct Wrapper<F>(F);
|
||||
|
||||
impl<F> Display for Wrapper<F>
|
||||
where
|
||||
F: Fn(&mut Formatter) -> std::fmt::Result,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
self.0(f)
|
||||
}
|
||||
}
|
||||
|
||||
Wrapper(f)
|
||||
}
|
||||
|
||||
/// Calculate a 128-bit siphash of a value.
|
||||
pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 {
|
||||
let mut state = SipHasher13::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user