Skip to content

Commit 7cd427a

Browse files
authored
Rename read_xml to from_xml (Azure#3218)
Also removes `read_xml_str()` that was unused.
1 parent b258df2 commit 7cd427a

File tree

9 files changed

+16
-27
lines changed

9 files changed

+16
-27
lines changed

sdk/core/azure_core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- Removed `constants` module.
1111
- Removed `CustomHeaders` policy.
1212
- Removed `ErrorKind::MockFramework`.
13+
- Removed `xml::read_xml_str()`.
14+
- Renamed `xml::read_xml()` to `xml::from_xml()` congruent with `json::from_json()`.
1315

1416
### Bugs Fixed
1517

sdk/core/azure_core/benches/deserialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn deserialize_list_blobs(c: &mut Criterion) {
6161
group.bench_function("xml", |b| {
6262
b.iter(|| {
6363
let _: ListBlobsFlatSegmentResponse =
64-
black_box(xml::read_xml(&blobs_xml).expect("deserialize xml"));
64+
black_box(xml::from_xml(&blobs_xml).expect("deserialize xml"));
6565
});
6666
});
6767
group.finish();

sdk/core/typespec/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
### Breaking Changes
88

99
- Removed `ErrorKind::MockFramework`.
10+
- Removed `xml::read_xml_str()`.
11+
- Renamed `xml::read_xml()` to `xml::from_xml()` congruent with `json::from_json()`.
1012

1113
### Bugs Fixed
1214

sdk/core/typespec/src/http/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl ResponseBody {
9393
where
9494
T: DeserializeOwned,
9595
{
96-
crate::xml::read_xml(&self.0)
96+
crate::xml::from_xml(&self.0)
9797
}
9898
}
9999

sdk/core/typespec/src/xml.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::error::{ErrorKind, Result, ResultExt};
66
use bytes::Bytes;
77
pub use quick_xml::serde_helpers::text_content as content;
88
use quick_xml::{
9-
de::{from_reader, from_str},
9+
de::from_reader,
1010
se::{to_string, to_string_with_root},
1111
};
1212
use serde::de::DeserializeOwned;
@@ -18,18 +18,7 @@ const UTF8_BOM: [u8; 3] = [0xEF, 0xBB, 0xBF];
1818
const DECLARATION: &[u8; 38] = br#"<?xml version="1.0" encoding="utf-8"?>"#;
1919

2020
/// Reads XML from bytes.
21-
pub fn read_xml_str<T>(body: &str) -> Result<T>
22-
where
23-
T: DeserializeOwned,
24-
{
25-
from_str(body).with_context_fn(ErrorKind::DataConversion, || {
26-
let t = core::any::type_name::<T>();
27-
format!("failed to deserialize the following xml into a {t}\n{body}")
28-
})
29-
}
30-
31-
/// Reads XML from bytes.
32-
pub fn read_xml<T>(body: &[u8]) -> Result<T>
21+
pub fn from_xml<T>(body: &[u8]) -> Result<T>
3322
where
3423
T: DeserializeOwned,
3524
{
@@ -110,15 +99,9 @@ mod test {
11099
x: "Hello, world!".into(),
111100
};
112101
let xml = br#"<?xml version="1.0" encoding="utf-8"?><Foo><x>Hello, world!</x></Foo>"#;
113-
assert_eq!(test, read_xml(xml)?);
114-
115-
let error = read_xml::<Test>(&xml[..xml.len() - 2]).unwrap_err();
116-
assert!(format!("{error}").contains("typespec::xml::test::Test"));
117-
118-
let xml = r#"<?xml version="1.0" encoding="utf-8"?><Foo><x>Hello, world!</x></Foo>"#;
119-
assert_eq!(test, read_xml_str(xml)?);
102+
assert_eq!(test, from_xml(xml)?);
120103

121-
let error = read_xml_str::<Test>(&xml[..xml.len() - 2]).unwrap_err();
104+
let error = from_xml::<Test>(&xml[..xml.len() - 2]).unwrap_err();
122105
assert!(format!("{error}").contains("typespec::xml::test::Test"));
123106
Ok(())
124107
}

sdk/core/typespec_client_core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- Moved deserializers and serializers for optional base64-encoded bytes to `base64::option` module. `base64` module now deserializes or serializes non-optional fields congruent with the `time` module.
1010
- Removed `CustomHeaders` policy.
1111
- Removed `ErrorKind::MockFramework`.
12+
- Removed `xml::read_xml_str()`.
13+
- Renamed `xml::read_xml()` to `xml::from_xml()` congruent with `json::from_json()`.
1214

1315
### Bugs Fixed
1416

sdk/storage/azure_storage_blob/src/generated/clients/blob_container_client.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_blob/src/generated/clients/blob_service_client.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/azure_storage_queue/src/generated/clients/queue_service_client.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)