Skip to content

feat!: CopyDataSource from static sources#941

Open
gibbz00 wants to merge 2 commits into
testcontainers:mainfrom
gibbz00:copy_data_source_ergonomics
Open

feat!: CopyDataSource from static sources#941
gibbz00 wants to merge 2 commits into
testcontainers:mainfrom
gibbz00:copy_data_source_ergonomics

Conversation

@gibbz00
Copy link
Copy Markdown

@gibbz00 gibbz00 commented May 1, 2026

This PR changes CopyDataSource::Data from containing a Vec<u8> to a Cow<'static, [u8]>, and then provides additional From<{&'static u8,&'static str,String}> implementation for it.

The motivation for this breaking change is admittedly mostly aesthetic.

fn new(config: impl Into<CopyDataSource>) -> SomeContainer;

const CONFIG: &str = r#"
  name = "foo"
  enabled = true
"#;

// Before:
let container = SomeContainer::new(CONFIG.as_bytes().to_vec());
// After:
let container = SomeContainer::new(CONFIG);

The first change will break compilation for projects that construct CopyDataSource directly with CopyDataSource::Data(vec). Those using impl Into<CopyDataSource> are unaffected by this change. Hopefully, most users construct CopyDataSource with the latter alternative. testcontainers-modules does this exclusively.

Another alternative could be to extend the enum with a third variant:

pub enum CopyDataSource {
    File(PathBuf),
    Data(Vec<u8>),
    StaticData(&'static u8),
}

This is also a breaking change, but only for those performing pattern matching on CopyDataSource, to which I assume a lot fewer do.

Completely understandable if this PR gets rejected given the questionable gains from such a breaking change ✌️

@netlify
Copy link
Copy Markdown

netlify Bot commented May 1, 2026

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit d7ae6af
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-rust/deploys/69f46f5dcb0c0b0008d5281b
😎 Deploy Preview https://deploy-preview-941--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gibbz00 gibbz00 changed the title Copy data source ergonomics feat!: CopyDataSource from static sources May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant