mirror of
https://github.com/typst/typst
synced 2025-07-27 06:17:53 +08:00
Migrate to 2024 edition
This commit is contained in:
parent
eed75ca4d6
commit
4bbd4e195b
@ -7,7 +7,7 @@ resolver = "2"
|
||||
version = "0.13.1"
|
||||
rust-version = "1.88" # also change in ci.yml
|
||||
authors = ["The Typst Project Developers"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
homepage = "https://typst.app"
|
||||
repository = "https://github.com/typst/typst"
|
||||
license = "Apache-2.0"
|
||||
|
@ -50,7 +50,7 @@ pub fn jump_from_click(
|
||||
}
|
||||
|
||||
// If there's no link, search for a jump target.
|
||||
for (mut pos, item) in frame.items().rev() {
|
||||
for &(mut pos, ref item) in frame.items().rev() {
|
||||
match item {
|
||||
FrameItem::Group(group) => {
|
||||
let pos = click - pos;
|
||||
@ -177,7 +177,7 @@ pub fn jump_from_cursor(
|
||||
|
||||
/// Find the position of a span in a frame.
|
||||
fn find_in_frame(frame: &Frame, span: Span) -> Option<Point> {
|
||||
for (mut pos, item) in frame.items() {
|
||||
for &(mut pos, ref item) in frame.items() {
|
||||
if let FrameItem::Group(group) = item {
|
||||
if let Some(point) = find_in_frame(&group.frame, span) {
|
||||
return Some(pos + point.transform(group.transform));
|
||||
|
@ -1228,7 +1228,7 @@ impl<'a> GridLayouter<'a> {
|
||||
.skip(parent.y)
|
||||
.take(rowspan)
|
||||
.rev()
|
||||
.find(|(_, &row)| row == Sizing::Auto)
|
||||
.find(|&(_, &row)| row == Sizing::Auto)
|
||||
.map(|(y, _)| y);
|
||||
|
||||
if last_spanned_auto_row != Some(y) {
|
||||
|
@ -55,7 +55,7 @@ pub fn layout_lr(
|
||||
|
||||
// Handle MathFragment::Glyph fragments that should be scaled up.
|
||||
for fragment in inner_fragments.iter_mut() {
|
||||
if let MathFragment::Glyph(ref mut glyph) = fragment {
|
||||
if let MathFragment::Glyph(glyph) = fragment {
|
||||
if glyph.mid_stretched == Some(false) {
|
||||
glyph.mid_stretched = Some(true);
|
||||
scale(ctx, fragment, relative_to, height);
|
||||
@ -95,7 +95,7 @@ pub fn layout_mid(
|
||||
let mut fragments = ctx.layout_into_fragments(&elem.body, styles)?;
|
||||
|
||||
for fragment in &mut fragments {
|
||||
if let MathFragment::Glyph(ref mut glyph) = fragment {
|
||||
if let MathFragment::Glyph(glyph) = fragment {
|
||||
glyph.mid_stretched = Some(false);
|
||||
glyph.class = MathClass::Relation;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ pub fn stretch_fragment(
|
||||
) {
|
||||
let size = fragment.size();
|
||||
|
||||
let MathFragment::Glyph(ref mut glyph) = fragment else { return };
|
||||
let MathFragment::Glyph(glyph) = fragment else { return };
|
||||
|
||||
// Return if we attempt to stretch along an axis which isn't stretchable,
|
||||
// so that the original fragment isn't modified.
|
||||
|
@ -47,7 +47,7 @@ impl Engine<'_> {
|
||||
}
|
||||
|
||||
/// Runs tasks on the engine in parallel.
|
||||
pub fn parallelize<P, I, T, U, F>(&mut self, iter: P, f: F) -> impl Iterator<Item = U>
|
||||
pub fn parallelize<P, I, T, U, F>(&mut self, iter: P, f: F) -> impl Iterator<Item = U> + use<P, I, T, U, F>
|
||||
where
|
||||
P: IntoIterator<IntoIter = I>,
|
||||
I: Iterator<Item = T>,
|
||||
|
@ -327,7 +327,7 @@ where
|
||||
self.0.entry(key).or_default().push(value);
|
||||
}
|
||||
|
||||
fn take(&mut self, key: &K) -> Option<impl Iterator<Item = V>> {
|
||||
fn take(&mut self, key: &K) -> Option<impl Iterator<Item = V> + use<K, V>> {
|
||||
self.0.remove(key).map(|vec| vec.into_iter())
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use crate::convert::GlobalContext;
|
||||
pub(crate) fn build_metadata(gc: &GlobalContext) -> Metadata {
|
||||
let creator = format!("Typst {}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
let lang = gc.languages.iter().max_by_key(|(_, &count)| count).map(|(&l, _)| l);
|
||||
let lang = gc.languages.iter().max_by_key(|&(_, &count)| count).map(|(&l, _)| l);
|
||||
|
||||
let dir = if lang.map(Lang::dir) == Some(Dir::RTL) {
|
||||
TextDirection::RightToLeft
|
||||
|
@ -16,11 +16,11 @@ use std::ptr::NonNull;
|
||||
/// to a value whose type implements the trait of `T` and the `vtable` must have
|
||||
/// been extracted with [`vtable`].
|
||||
#[track_caller]
|
||||
pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *const T {
|
||||
pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *const T { unsafe {
|
||||
let fat = FatPointer { data, vtable };
|
||||
debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
|
||||
mem::transmute_copy::<FatPointer, *const T>(&fat)
|
||||
}
|
||||
}}
|
||||
|
||||
/// Create a mutable fat pointer from a data address and a vtable address.
|
||||
///
|
||||
@ -29,23 +29,23 @@ pub unsafe fn from_raw_parts<T: ?Sized>(data: *const (), vtable: *const ()) -> *
|
||||
/// to a value whose type implements the trait of `T` and the `vtable` must have
|
||||
/// been extracted with [`vtable`].
|
||||
#[track_caller]
|
||||
pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) -> *mut T {
|
||||
pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) -> *mut T { unsafe {
|
||||
let fat = FatPointer { data, vtable };
|
||||
debug_assert_eq!(Layout::new::<*mut T>(), Layout::new::<FatPointer>());
|
||||
mem::transmute_copy::<FatPointer, *mut T>(&fat)
|
||||
}
|
||||
}}
|
||||
|
||||
/// Extract the address to a trait object's vtable.
|
||||
///
|
||||
/// # Safety
|
||||
/// Must only be called when `T` is a `dyn Trait`.
|
||||
#[track_caller]
|
||||
pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> NonNull<()> {
|
||||
pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> NonNull<()> { unsafe {
|
||||
debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
|
||||
NonNull::new_unchecked(
|
||||
mem::transmute_copy::<*const T, FatPointer>(&ptr).vtable as *mut (),
|
||||
)
|
||||
}
|
||||
}}
|
||||
|
||||
/// The memory representation of a trait object pointer.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user