Skip to content

Commit d83fcd8

Browse files
committed
Make RemoteSettingsClient::get_attachment input a reference
This won't change anything when it's called from UniFFI since we still need to copy the data to pass it over the FFI. However, we're starting to use this client internally as well and this makes it so we can avoid a copy when calling the method from Rust.
1 parent 1fa3a0f commit d83fcd8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

components/remote_settings/src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,10 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
372372

373373
/// Downloads an attachment from [attachment_location]. NOTE: there are no guarantees about a
374374
/// maximum size, so use care when fetching potentially large attachments.
375-
pub fn get_attachment(&self, record: RemoteSettingsRecord) -> Result<Vec<u8>> {
375+
pub fn get_attachment(&self, record: &RemoteSettingsRecord) -> Result<Vec<u8>> {
376376
let metadata = record
377377
.attachment
378+
.as_ref()
378379
.ok_or_else(|| Error::RecordAttachmentMismatchError("No attachment metadata".into()))?;
379380

380381
let mut inner = self.inner.lock();
@@ -2427,7 +2428,7 @@ mod test_packaged_metadata {
24272428
fields: serde_json::json!({}).as_object().unwrap().clone(),
24282429
};
24292430

2430-
let attachment_data = rs_client.get_attachment(record)?;
2431+
let attachment_data = rs_client.get_attachment(&record)?;
24312432

24322433
// Verify we got the expected data
24332434
let expected_data = std::fs::read(file_path)?;
@@ -2483,7 +2484,7 @@ mod test_packaged_metadata {
24832484
fields: serde_json::json!({}).as_object().unwrap().clone(),
24842485
};
24852486

2486-
let attachment_data = rs_client.get_attachment(record)?;
2487+
let attachment_data = rs_client.get_attachment(&record)?;
24872488

24882489
// Verify we got the mock API data, not the packaged data
24892490
assert_eq!(attachment_data, vec![1, 2, 3, 4, 5]);

components/remote_settings/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl RemoteSettingsClient {
196196
/// - This method will throw if there is a network or other error when fetching the
197197
/// attachment data.
198198
#[handle_error(Error)]
199-
pub fn get_attachment(&self, record: RemoteSettingsRecord) -> ApiResult<Vec<u8>> {
199+
pub fn get_attachment(&self, record: &RemoteSettingsRecord) -> ApiResult<Vec<u8>> {
200200
self.internal.get_attachment(record)
201201
}
202202
}

0 commit comments

Comments
 (0)