Move a slide to a new position in a presentation

Slide order is controlled by the order of <p:sldId/> elements in the presentation part. Moving a slide does not require changing the slide XML; it requires reordering the slide id list while preserving the same relationship ids.

Slide order markup

<p:sldIdLst>
  <p:sldId id="256" r:id="rId1"/>
  <p:sldId id="257" r:id="rId2"/>
  <p:sldId id="258" r:id="rId3"/>
</p:sldIdLst>

Moving the third slide to the first position means moving the rId3 entry before rId1.

The upstream sample treats both from and to as zero-based indexes. It first counts slides, verifies both indexes are in range and different, removes the source p:sldId entry, and inserts that same entry at the target position. The slide part and relationship ID are preserved.

Rust workflow

#![allow(unused)]
fn main() {
pub fn move_slide_to_position(
  path: &Path,
  from_index: usize,
  to_index: usize,
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
  let mut document = PresentationDocument::new_from_file_with_settings(path, lazy_settings())?;
  let presentation_part = document.presentation_part()?;
  let xml = presentation_part
    .data_as_str(&document)?
    .unwrap_or_default();
  let updated_xml = reorder_slide_ids(xml, from_index, to_index)?;

  presentation_part.set_data(&mut document, updated_xml.into_bytes())?;

  let mut buffer = Cursor::new(Vec::new());
  document.save(&mut buffer)?;
  Ok(buffer.into_inner())
}
}

The listing reorders only the <p:sldId/> children, preserves the slide ids and relationship ids, saves the package, and verifies that slide relationships still resolve.