Skip to main content

Slides

Struct Slides 

Source
pub struct Slides { /* private fields */ }
Expand description

Slides —— crate::presentation::Presentation 上的幻灯片集合。

§内部表示

仅持有一个 Vec<SlideEntry>,每个 entry 包含:

  • sld:高阶 Slide
  • sld_idsldIdLst 中用到的 id(一般从 256 开始递增);
  • rid:与 presentation.xml.rels 中的 <Relationship Id="..."/> 对应;
  • partname:相对 zip 根的 part 路径(如 /ppt/slides/slide1.xml)。

Implementations§

Source§

impl Slides

Source

pub fn new() -> Self

新建一个空集合。

Source

pub fn len(&self) -> usize

数量。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

pub fn iter(&self) -> Iter<'_, SlideEntry>

遍历所有 entry。

Source

pub fn get(&self, idx: usize) -> Option<&SlideEntry>

按下标取不可变 entry。

Source

pub fn get_mut(&mut self, idx: usize) -> Option<&mut SlideEntry>

按下标取可变 entry。

Source

pub fn add_slide(&mut self, id_counter: Rc<Cell<u32>>) -> Result<&mut Slide>

添加一个新 slide(空白)。

返回新 slide 的可变引用,调用方可继续 shapes_mut().add_*(...)id_counter 必须从 crate::presentation::Presentation::id_counter 传入。

默认使用第一个 layout(索引 0)。如需指定版式,调用 Slides::add_slide_with_layout

Source

pub fn add_slide_with_layout( &mut self, id_counter: Rc<Cell<u32>>, layout_idx: usize, ) -> Result<&mut Slide>

添加一个新 slide,并指定使用的版式索引(对应 SlideLayouts[i])。

§参数
  • id_counter:全局 shape id 计数器(必须与所属 Presentation 共享);
  • layout_idx:版式索引。<= 0 时退化为 0;越界会被钳制为最后一个。
§行为
  • 新 slide 的 layout_rid 形如 rIdLayout<N>
  • 在保存时 presentation.xml<p:sldIdLst/> 内会按调用顺序排列。
Source

pub fn remove(&mut self, idx: usize) -> Option<Slide>

按下标移除。

对标 python-pptx Presentation.slides._sldIdLst.remove(index)。 返回被移除的 Slide;越界返回 None

Source

pub fn move_slide(&mut self, from_idx: usize, to_idx: usize) -> Result<()>

将幻灯片从 from_idx 移动到 to_idx,实现重排序。

对标 python-pptx 中通过 XML 操作调整 sldIdLst 子元素顺序的能力。

§参数
  • from_idx:源位置索引(0-based);
  • to_idx:目标位置索引(0-based,基于移除前的长度)。
§行为
  • 越界时返回 Err(IndexOutOfRange)
  • from_idx == to_idx 时为 no-op;
  • 移动后所有 sld_id / rid / partname 会重新分配(调用 reindex)。
§示例
// 将第 0 张移到末尾
p.slides_mut().move_slide(0, 2).unwrap();
Source

pub fn reorder(&mut self, indices: &[usize]) -> Result<()>

按给定索引顺序批量重排幻灯片。

对标 python-pptx 中通过 XML 操作批量调整 sldIdLst 子元素顺序的能力。

§参数
  • indices:新顺序的索引列表(基于重排前的位置)。长度必须等于当前幻灯片数, 且每个索引在 [0, len) 范围内、不重复、全覆盖。
§行为
  • 验证失败时返回 Err不修改当前顺序;
  • 重排后所有 sld_id / rid / partname 会重新分配(调用 reindex)。
§示例
// 反转顺序:[0,1,2] -> [2,1,0]
p.slides_mut().reorder(&[2, 1, 0]).unwrap();
Source

pub fn insert_slide( &mut self, id_counter: Rc<Cell<u32>>, index: usize, ) -> Result<&mut Slide>

在指定位置插入一个空白 slide。

对标 pypdf PdfWriter.insert_page(index) / python-pptx 中通过 XML 操作在 sldIdLst 中间插入条目的能力。

§参数
  • id_counter:全局 shape id 计数器;
  • index:插入位置(0 = 最前,len = 末尾,等价于 add_slide)。
§注意

插入后所有 sld_id / rid / partname重新分配—— 因为 OOXML 的 sldIdLst 要求 id 单调递增。调用方不应依赖 插入前的 sld_id / rid 值。

Source

pub fn clone_slide( &mut self, src_idx: usize, insert_at: usize, ) -> Result<&mut Slide>

克隆一个已有 slide 到指定位置。

对标 pypdf PdfWriter.clone_page_from_reader + insert_page。 深拷贝源 slide 的所有形状、文本、备注等,但分配新的 id / rid / partname。

§参数
  • src_idx:源 slide 索引;
  • insert_at:目标位置(len = 末尾)。
Source

pub fn append_slides_from(&mut self, other: &Slides)

从另一个 Slides 集合追加所有 slide(深拷贝)。

对标 pypdf PdfWriter.append_pages_from_reader。 每个源 slide 被深拷贝后追加到当前集合末尾。

§注意
  • 源 slide 的 id_counter 不会被共享——新 slide 使用 当前集合的 id_counter
  • 追加后所有 sld_id / rid / partname 重新分配。
Source

pub fn index_of(&self, sld: &Slide) -> Option<usize>

按引用找到第一个匹配的 slide 索引。

形如 python-pptx 中 slides.index(slide)未找到返回 None(不抛异常), 与 python-pptx 略不同——但更符合 Rust 的“零异常“习惯。

Trait Implementations§

Source§

impl Debug for Slides

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Slides

Source§

fn default() -> Slides

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Slides

§

impl !Send for Slides

§

impl !Sync for Slides

§

impl !UnwindSafe for Slides

§

impl Freeze for Slides

§

impl Unpin for Slides

§

impl UnsafeUnpin for Slides

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V