Skip to main content

azure_storage_blob/generated/clients/
page_blob_client.rs

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3//
4// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT.
5
6use crate::{
7    generated::models::{
8        PageBlobClientClearPagesOptions, PageBlobClientClearPagesResult,
9        PageBlobClientCreateOptions, PageBlobClientCreateResult,
10        PageBlobClientListPageRangesOptions, PageBlobClientResizeOptions,
11        PageBlobClientResizeResult, PageBlobClientSetSequenceNumberOptions,
12        PageBlobClientSetSequenceNumberResult, PageBlobClientUploadPagesFromUrlOptions,
13        PageBlobClientUploadPagesFromUrlResult, PageBlobClientUploadPagesOptions,
14        PageBlobClientUploadPagesResult, PageList, SequenceNumberActionType,
15    },
16    models::HttpRange,
17};
18use azure_core::{
19    base64,
20    error::CheckSuccessOptions,
21    fmt::SafeDebug,
22    http::{
23        pager::{PagerContinuation, PagerResult, PagerState},
24        ClientOptions, Method, NoFormat, PageIterator, Pipeline, PipelineSendOptions, RawResponse,
25        Request, RequestContent, Response, Url, UrlExt, XmlFormat,
26    },
27    time::to_rfc7231,
28    tracing, xml, Bytes, Result,
29};
30
31#[tracing::client]
32pub struct PageBlobClient {
33    pub(crate) endpoint: Url,
34    pub(crate) pipeline: Pipeline,
35    pub(crate) version: String,
36}
37
38/// Options used when creating a `PageBlobClient`
39#[derive(Clone, SafeDebug)]
40pub struct PageBlobClientOptions {
41    /// Allows customization of the client.
42    pub client_options: ClientOptions,
43    /// Specifies the version of the operation to use for this request.
44    pub version: String,
45}
46
47impl PageBlobClient {
48    /// Clears a range of pages from the specified page blob.
49    ///
50    /// # Arguments
51    ///
52    /// * `range` - Specifies the range of the blob to operate on.
53    /// * `options` - Optional parameters for the request.
54    ///
55    /// ## Response Headers
56    ///
57    /// The returned [`Response`](azure_core::http::Response) implements the [`PageBlobClientClearPagesResultHeaders`] trait, which provides
58    /// access to response headers. For example:
59    ///
60    /// ```no_run
61    /// use azure_core::{Result, http::{Response, NoFormat}};
62    /// use azure_storage_blob::models::{PageBlobClientClearPagesResult, PageBlobClientClearPagesResultHeaders};
63    /// async fn example() -> Result<()> {
64    ///     let response: Response<PageBlobClientClearPagesResult, NoFormat> = unimplemented!();
65    ///     // Access response headers
66    ///     if let Some(content_md5) = response.content_md5()? {
67    ///         println!("content-md5: {:?}", content_md5);
68    ///     }
69    ///     if let Some(etag) = response.etag()? {
70    ///         println!("etag: {:?}", etag);
71    ///     }
72    ///     if let Some(last_modified) = response.last_modified()? {
73    ///         println!("last-modified: {:?}", last_modified);
74    ///     }
75    ///     Ok(())
76    /// }
77    /// ```
78    ///
79    /// ### Available headers
80    /// * [`content_md5`()](crate::generated::models::PageBlobClientClearPagesResultHeaders::content_md5) - content-md5
81    /// * [`etag`()](crate::generated::models::PageBlobClientClearPagesResultHeaders::etag) - etag
82    /// * [`last_modified`()](crate::generated::models::PageBlobClientClearPagesResultHeaders::last_modified) - last-modified
83    /// * [`blob_sequence_number`()](crate::generated::models::PageBlobClientClearPagesResultHeaders::blob_sequence_number) - x-ms-blob-sequence-number
84    /// * [`content_crc64`()](crate::generated::models::PageBlobClientClearPagesResultHeaders::content_crc64) - x-ms-content-crc64
85    ///
86    /// [`PageBlobClientClearPagesResultHeaders`]: crate::generated::models::PageBlobClientClearPagesResultHeaders
87    #[tracing::function("Storage.Blob.PageBlobClient.clearPages")]
88    pub async fn clear_pages(
89        &self,
90        range: HttpRange,
91        options: Option<PageBlobClientClearPagesOptions<'_>>,
92    ) -> Result<Response<PageBlobClientClearPagesResult, NoFormat>> {
93        let options = options.unwrap_or_default();
94        let ctx = options.method_options.context.to_borrowed();
95        let mut url = self.endpoint.clone();
96        let mut query_builder = url.query_builder();
97        query_builder.append_pair("comp", "page");
98        if let Some(timeout) = options.timeout {
99            query_builder.set_pair("timeout", timeout.to_string());
100        }
101        query_builder.build();
102        let mut request = Request::new(url, Method::Put);
103        request.insert_header("content-length", "0");
104        if let Some(if_match) = options.if_match.as_ref() {
105            request.insert_header("if-match", if_match.to_string());
106        }
107        if let Some(if_modified_since) = options.if_modified_since {
108            request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
109        }
110        if let Some(if_none_match) = options.if_none_match.as_ref() {
111            request.insert_header("if-none-match", if_none_match.to_string());
112        }
113        if let Some(if_unmodified_since) = options.if_unmodified_since {
114            request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
115        }
116        request.insert_header("range", range.to_string());
117        if let Some(encryption_algorithm) = options.encryption_algorithm.as_ref() {
118            request.insert_header(
119                "x-ms-encryption-algorithm",
120                encryption_algorithm.to_string(),
121            );
122        }
123        if let Some(encryption_key) = options.encryption_key.as_ref() {
124            request.insert_header("x-ms-encryption-key", encryption_key);
125        }
126        if let Some(encryption_key_sha256) = options.encryption_key_sha256.as_ref() {
127            request.insert_header("x-ms-encryption-key-sha256", encryption_key_sha256);
128        }
129        if let Some(encryption_scope) = options.encryption_scope.as_ref() {
130            request.insert_header("x-ms-encryption-scope", encryption_scope);
131        }
132        if let Some(if_sequence_number_equal_to) = options.if_sequence_number_equal_to {
133            request.insert_header(
134                "x-ms-if-sequence-number-eq",
135                if_sequence_number_equal_to.to_string(),
136            );
137        }
138        if let Some(if_sequence_number_less_than_or_equal_to) =
139            options.if_sequence_number_less_than_or_equal_to
140        {
141            request.insert_header(
142                "x-ms-if-sequence-number-le",
143                if_sequence_number_less_than_or_equal_to.to_string(),
144            );
145        }
146        if let Some(if_sequence_number_less_than) = options.if_sequence_number_less_than {
147            request.insert_header(
148                "x-ms-if-sequence-number-lt",
149                if_sequence_number_less_than.to_string(),
150            );
151        }
152        if let Some(if_tags) = options.if_tags.as_ref() {
153            request.insert_header("x-ms-if-tags", if_tags);
154        }
155        if let Some(lease_id) = options.lease_id.as_ref() {
156            request.insert_header("x-ms-lease-id", lease_id);
157        }
158        request.insert_header("x-ms-page-write", "clear");
159        request.insert_header("x-ms-version", &self.version);
160        let rsp = self
161            .pipeline
162            .send(
163                &ctx,
164                &mut request,
165                Some(PipelineSendOptions {
166                    check_success: CheckSuccessOptions {
167                        success_codes: &[201],
168                    },
169                    ..Default::default()
170                }),
171            )
172            .await?;
173        Ok(rsp.into())
174    }
175
176    /// Creates a new page blob.
177    ///
178    /// # Arguments
179    ///
180    /// * `size` - The maximum size for the page blob. Must be aligned to a 512-byte boundary.
181    /// * `options` - Optional parameters for the request.
182    ///
183    /// ## Response Headers
184    ///
185    /// The returned [`Response`](azure_core::http::Response) implements the [`PageBlobClientCreateResultHeaders`] trait, which provides
186    /// access to response headers. For example:
187    ///
188    /// ```no_run
189    /// use azure_core::{Result, http::{Response, NoFormat}};
190    /// use azure_storage_blob::models::{PageBlobClientCreateResult, PageBlobClientCreateResultHeaders};
191    /// async fn example() -> Result<()> {
192    ///     let response: Response<PageBlobClientCreateResult, NoFormat> = unimplemented!();
193    ///     // Access response headers
194    ///     if let Some(content_md5) = response.content_md5()? {
195    ///         println!("content-md5: {:?}", content_md5);
196    ///     }
197    ///     if let Some(etag) = response.etag()? {
198    ///         println!("etag: {:?}", etag);
199    ///     }
200    ///     if let Some(last_modified) = response.last_modified()? {
201    ///         println!("last-modified: {:?}", last_modified);
202    ///     }
203    ///     Ok(())
204    /// }
205    /// ```
206    ///
207    /// ### Available headers
208    /// * [`content_md5`()](crate::generated::models::PageBlobClientCreateResultHeaders::content_md5) - content-md5
209    /// * [`etag`()](crate::generated::models::PageBlobClientCreateResultHeaders::etag) - etag
210    /// * [`last_modified`()](crate::generated::models::PageBlobClientCreateResultHeaders::last_modified) - last-modified
211    /// * [`encryption_key_sha256`()](crate::generated::models::PageBlobClientCreateResultHeaders::encryption_key_sha256) - x-ms-encryption-key-sha256
212    /// * [`encryption_scope`()](crate::generated::models::PageBlobClientCreateResultHeaders::encryption_scope) - x-ms-encryption-scope
213    /// * [`is_server_encrypted`()](crate::generated::models::PageBlobClientCreateResultHeaders::is_server_encrypted) - x-ms-request-server-encrypted
214    /// * [`version_id`()](crate::generated::models::PageBlobClientCreateResultHeaders::version_id) - x-ms-version-id
215    ///
216    /// [`PageBlobClientCreateResultHeaders`]: crate::generated::models::PageBlobClientCreateResultHeaders
217    #[tracing::function("Storage.Blob.PageBlobClient.create")]
218    pub async fn create(
219        &self,
220        size: u64,
221        options: Option<PageBlobClientCreateOptions<'_>>,
222    ) -> Result<Response<PageBlobClientCreateResult, NoFormat>> {
223        let options = options.unwrap_or_default();
224        let ctx = options.method_options.context.to_borrowed();
225        let mut url = self.endpoint.clone();
226        let mut query_builder = url.query_builder();
227        if let Some(timeout) = options.timeout {
228            query_builder.set_pair("timeout", timeout.to_string());
229        }
230        query_builder.build();
231        let mut request = Request::new(url, Method::Put);
232        request.insert_header("content-length", "0");
233        if let Some(if_match) = options.if_match.as_ref() {
234            request.insert_header("if-match", if_match.to_string());
235        }
236        if let Some(if_modified_since) = options.if_modified_since {
237            request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
238        }
239        if let Some(if_none_match) = options.if_none_match.as_ref() {
240            request.insert_header("if-none-match", if_none_match.to_string());
241        }
242        if let Some(if_unmodified_since) = options.if_unmodified_since {
243            request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
244        }
245        if let Some(tier) = options.tier.as_ref() {
246            request.insert_header("x-ms-access-tier", tier.to_string());
247        }
248        if let Some(blob_cache_control) = options.blob_cache_control.as_ref() {
249            request.insert_header("x-ms-blob-cache-control", blob_cache_control);
250        }
251        if let Some(blob_content_disposition) = options.blob_content_disposition.as_ref() {
252            request.insert_header("x-ms-blob-content-disposition", blob_content_disposition);
253        }
254        if let Some(blob_content_encoding) = options.blob_content_encoding.as_ref() {
255            request.insert_header("x-ms-blob-content-encoding", blob_content_encoding);
256        }
257        if let Some(blob_content_language) = options.blob_content_language.as_ref() {
258            request.insert_header("x-ms-blob-content-language", blob_content_language);
259        }
260        request.insert_header("x-ms-blob-content-length", size.to_string());
261        if let Some(blob_content_md5) = options.blob_content_md5 {
262            request.insert_header("x-ms-blob-content-md5", base64::encode(blob_content_md5));
263        }
264        if let Some(blob_content_type) = options.blob_content_type.as_ref() {
265            request.insert_header("x-ms-blob-content-type", blob_content_type);
266        }
267        if let Some(blob_sequence_number) = options.blob_sequence_number {
268            request.insert_header(
269                "x-ms-blob-sequence-number",
270                blob_sequence_number.to_string(),
271            );
272        }
273        request.insert_header("x-ms-blob-type", "PageBlob");
274        if let Some(encryption_algorithm) = options.encryption_algorithm.as_ref() {
275            request.insert_header(
276                "x-ms-encryption-algorithm",
277                encryption_algorithm.to_string(),
278            );
279        }
280        if let Some(encryption_key) = options.encryption_key.as_ref() {
281            request.insert_header("x-ms-encryption-key", encryption_key);
282        }
283        if let Some(encryption_key_sha256) = options.encryption_key_sha256.as_ref() {
284            request.insert_header("x-ms-encryption-key-sha256", encryption_key_sha256);
285        }
286        if let Some(encryption_scope) = options.encryption_scope.as_ref() {
287            request.insert_header("x-ms-encryption-scope", encryption_scope);
288        }
289        if let Some(if_tags) = options.if_tags.as_ref() {
290            request.insert_header("x-ms-if-tags", if_tags);
291        }
292        if let Some(immutability_policy_mode) = options.immutability_policy_mode.as_ref() {
293            request.insert_header(
294                "x-ms-immutability-policy-mode",
295                immutability_policy_mode.to_string(),
296            );
297        }
298        if let Some(immutability_policy_expiry) = options.immutability_policy_expiry {
299            request.insert_header(
300                "x-ms-immutability-policy-until-date",
301                to_rfc7231(&immutability_policy_expiry),
302            );
303        }
304        if let Some(lease_id) = options.lease_id.as_ref() {
305            request.insert_header("x-ms-lease-id", lease_id);
306        }
307        if let Some(legal_hold) = options.legal_hold {
308            request.insert_header("x-ms-legal-hold", legal_hold.to_string());
309        }
310        if let Some(metadata) = options.metadata.as_ref() {
311            for (k, v) in metadata {
312                request.insert_header(format!("x-ms-meta-{k}"), v);
313            }
314        }
315        if let Some(blob_tags_string) = options.blob_tags_string.as_ref() {
316            request.insert_header("x-ms-tags", blob_tags_string);
317        }
318        request.insert_header("x-ms-version", &self.version);
319        let rsp = self
320            .pipeline
321            .send(
322                &ctx,
323                &mut request,
324                Some(PipelineSendOptions {
325                    check_success: CheckSuccessOptions {
326                        success_codes: &[201],
327                    },
328                    ..Default::default()
329                }),
330            )
331            .await?;
332        Ok(rsp.into())
333    }
334
335    /// Returns the list of valid page ranges for the specified page blob.
336    ///
337    /// # Arguments
338    ///
339    /// * `options` - Optional parameters for the request.
340    ///
341    /// ## Response Headers
342    ///
343    /// The returned [`Response`](azure_core::http::Response) implements the [`PageListHeaders`] trait, which provides
344    /// access to response headers. For example:
345    ///
346    /// ```no_run
347    /// use azure_core::{Result, http::{Response, XmlFormat}};
348    /// use azure_storage_blob::models::{PageList, PageListHeaders};
349    /// async fn example() -> Result<()> {
350    ///     let response: Response<PageList, XmlFormat> = unimplemented!();
351    ///     // Access response headers
352    ///     if let Some(etag) = response.etag()? {
353    ///         println!("etag: {:?}", etag);
354    ///     }
355    ///     if let Some(last_modified) = response.last_modified()? {
356    ///         println!("last-modified: {:?}", last_modified);
357    ///     }
358    ///     if let Some(blob_content_length) = response.blob_content_length()? {
359    ///         println!("x-ms-blob-content-length: {:?}", blob_content_length);
360    ///     }
361    ///     Ok(())
362    /// }
363    /// ```
364    ///
365    /// ### Available headers
366    /// * [`etag`()](crate::generated::models::PageListHeaders::etag) - etag
367    /// * [`last_modified`()](crate::generated::models::PageListHeaders::last_modified) - last-modified
368    /// * [`blob_content_length`()](crate::generated::models::PageListHeaders::blob_content_length) - x-ms-blob-content-length
369    ///
370    /// [`PageListHeaders`]: crate::generated::models::PageListHeaders
371    #[tracing::function("Storage.Blob.PageBlobClient.getPageRanges")]
372    pub fn list_page_ranges(
373        &self,
374        options: Option<PageBlobClientListPageRangesOptions<'_>>,
375    ) -> Result<PageIterator<Response<PageList, XmlFormat>>> {
376        let options = options.unwrap_or_default().into_owned();
377        let pipeline = self.pipeline.clone();
378        let mut first_url = self.endpoint.clone();
379        let mut query_builder = first_url.query_builder();
380        query_builder.append_pair("comp", "pagelist");
381        if let Some(marker) = options.marker.as_ref() {
382            query_builder.set_pair("marker", marker);
383        }
384        if let Some(maxresults) = options.maxresults {
385            query_builder.set_pair("maxresults", maxresults.to_string());
386        }
387        if let Some(snapshot) = options.snapshot.as_ref() {
388            query_builder.set_pair("snapshot", snapshot);
389        }
390        if let Some(timeout) = options.timeout {
391            query_builder.set_pair("timeout", timeout.to_string());
392        }
393        query_builder.build();
394        #[derive(serde::Deserialize)]
395        struct PageBlobClientListPageRangesPage {
396            #[serde(rename = "NextMarker")]
397            next_marker: Option<String>,
398        }
399
400        let version = self.version.clone();
401        Ok(PageIterator::new(
402            move |marker: PagerState, pager_options| {
403                let mut url = first_url.clone();
404                if let PagerState::More(marker) = marker {
405                    let mut query_builder = url.query_builder();
406                    query_builder.set_pair("marker", marker.as_ref());
407                    query_builder.build();
408                }
409                let mut request = Request::new(url, Method::Get);
410                request.insert_header("accept", "application/xml");
411                if let Some(if_match) = options.if_match.as_ref() {
412                    request.insert_header("if-match", if_match.to_string());
413                }
414                if let Some(if_modified_since) = options.if_modified_since {
415                    request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
416                }
417                if let Some(if_none_match) = options.if_none_match.as_ref() {
418                    request.insert_header("if-none-match", if_none_match.to_string());
419                }
420                if let Some(if_unmodified_since) = options.if_unmodified_since {
421                    request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
422                }
423                if let Some(range) = options.range.as_ref() {
424                    request.insert_header("range", range.to_string());
425                }
426                if let Some(if_tags) = options.if_tags.as_ref() {
427                    request.insert_header("x-ms-if-tags", if_tags);
428                }
429                if let Some(lease_id) = options.lease_id.as_ref() {
430                    request.insert_header("x-ms-lease-id", lease_id);
431                }
432                request.insert_header("x-ms-version", &version);
433                let pipeline = pipeline.clone();
434                Box::pin(async move {
435                    let rsp = pipeline
436                        .send(
437                            &pager_options.context,
438                            &mut request,
439                            Some(PipelineSendOptions {
440                                check_success: CheckSuccessOptions {
441                                    success_codes: &[200],
442                                },
443                                ..Default::default()
444                            }),
445                        )
446                        .await?;
447                    let (status, headers, body) = rsp.deconstruct();
448                    let res: PageBlobClientListPageRangesPage = xml::from_xml(&body)?;
449                    let rsp = RawResponse::from_bytes(status, headers, body).into();
450                    Ok(match res.next_marker {
451                        Some(next_marker) if !next_marker.is_empty() => PagerResult::More {
452                            response: rsp,
453                            continuation: PagerContinuation::Token(next_marker),
454                        },
455                        _ => PagerResult::Done { response: rsp },
456                    })
457                })
458            },
459            Some(options.method_options),
460        ))
461    }
462
463    /// Changes the size of the specified page blob.
464    ///
465    /// # Arguments
466    ///
467    /// * `size` - The maximum size for the page blob. Must be aligned to a 512-byte boundary.
468    /// * `options` - Optional parameters for the request.
469    ///
470    /// ## Response Headers
471    ///
472    /// The returned [`Response`](azure_core::http::Response) implements the [`PageBlobClientResizeResultHeaders`] trait, which provides
473    /// access to response headers. For example:
474    ///
475    /// ```no_run
476    /// use azure_core::{Result, http::{Response, NoFormat}};
477    /// use azure_storage_blob::models::{PageBlobClientResizeResult, PageBlobClientResizeResultHeaders};
478    /// async fn example() -> Result<()> {
479    ///     let response: Response<PageBlobClientResizeResult, NoFormat> = unimplemented!();
480    ///     // Access response headers
481    ///     if let Some(etag) = response.etag()? {
482    ///         println!("etag: {:?}", etag);
483    ///     }
484    ///     if let Some(last_modified) = response.last_modified()? {
485    ///         println!("last-modified: {:?}", last_modified);
486    ///     }
487    ///     if let Some(blob_sequence_number) = response.blob_sequence_number()? {
488    ///         println!("x-ms-blob-sequence-number: {:?}", blob_sequence_number);
489    ///     }
490    ///     Ok(())
491    /// }
492    /// ```
493    ///
494    /// ### Available headers
495    /// * [`etag`()](crate::generated::models::PageBlobClientResizeResultHeaders::etag) - etag
496    /// * [`last_modified`()](crate::generated::models::PageBlobClientResizeResultHeaders::last_modified) - last-modified
497    /// * [`blob_sequence_number`()](crate::generated::models::PageBlobClientResizeResultHeaders::blob_sequence_number) - x-ms-blob-sequence-number
498    ///
499    /// [`PageBlobClientResizeResultHeaders`]: crate::generated::models::PageBlobClientResizeResultHeaders
500    #[tracing::function("Storage.Blob.PageBlobClient.resize")]
501    pub async fn resize(
502        &self,
503        size: u64,
504        options: Option<PageBlobClientResizeOptions<'_>>,
505    ) -> Result<Response<PageBlobClientResizeResult, NoFormat>> {
506        let options = options.unwrap_or_default();
507        let ctx = options.method_options.context.to_borrowed();
508        let mut url = self.endpoint.clone();
509        let mut query_builder = url.query_builder();
510        query_builder.append_pair("comp", "properties");
511        if let Some(timeout) = options.timeout {
512            query_builder.set_pair("timeout", timeout.to_string());
513        }
514        query_builder.build();
515        let mut request = Request::new(url, Method::Put);
516        if let Some(if_match) = options.if_match.as_ref() {
517            request.insert_header("if-match", if_match.to_string());
518        }
519        if let Some(if_modified_since) = options.if_modified_since {
520            request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
521        }
522        if let Some(if_none_match) = options.if_none_match.as_ref() {
523            request.insert_header("if-none-match", if_none_match.to_string());
524        }
525        if let Some(if_unmodified_since) = options.if_unmodified_since {
526            request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
527        }
528        request.insert_header("x-ms-blob-content-length", size.to_string());
529        if let Some(encryption_algorithm) = options.encryption_algorithm.as_ref() {
530            request.insert_header(
531                "x-ms-encryption-algorithm",
532                encryption_algorithm.to_string(),
533            );
534        }
535        if let Some(encryption_key) = options.encryption_key.as_ref() {
536            request.insert_header("x-ms-encryption-key", encryption_key);
537        }
538        if let Some(encryption_key_sha256) = options.encryption_key_sha256.as_ref() {
539            request.insert_header("x-ms-encryption-key-sha256", encryption_key_sha256);
540        }
541        if let Some(encryption_scope) = options.encryption_scope.as_ref() {
542            request.insert_header("x-ms-encryption-scope", encryption_scope);
543        }
544        if let Some(if_tags) = options.if_tags.as_ref() {
545            request.insert_header("x-ms-if-tags", if_tags);
546        }
547        if let Some(lease_id) = options.lease_id.as_ref() {
548            request.insert_header("x-ms-lease-id", lease_id);
549        }
550        request.insert_header("x-ms-version", &self.version);
551        let rsp = self
552            .pipeline
553            .send(
554                &ctx,
555                &mut request,
556                Some(PipelineSendOptions {
557                    check_success: CheckSuccessOptions {
558                        success_codes: &[200],
559                    },
560                    ..Default::default()
561                }),
562            )
563            .await?;
564        Ok(rsp.into())
565    }
566
567    /// Updates the sequence number of the specified page blob. The operation will fail if the specified sequence number is less
568    /// than the current sequence number of the blob.
569    ///
570    /// # Arguments
571    ///
572    /// * `sequence_number_action` - Required if the blob sequence number is provided. This property indicates how the service
573    ///   should modify the blob's sequence number.
574    /// * `options` - Optional parameters for the request.
575    ///
576    /// ## Response Headers
577    ///
578    /// The returned [`Response`](azure_core::http::Response) implements the [`PageBlobClientSetSequenceNumberResultHeaders`] trait, which provides
579    /// access to response headers. For example:
580    ///
581    /// ```no_run
582    /// use azure_core::{Result, http::{Response, NoFormat}};
583    /// use azure_storage_blob::models::{PageBlobClientSetSequenceNumberResult, PageBlobClientSetSequenceNumberResultHeaders};
584    /// async fn example() -> Result<()> {
585    ///     let response: Response<PageBlobClientSetSequenceNumberResult, NoFormat> = unimplemented!();
586    ///     // Access response headers
587    ///     if let Some(etag) = response.etag()? {
588    ///         println!("etag: {:?}", etag);
589    ///     }
590    ///     if let Some(last_modified) = response.last_modified()? {
591    ///         println!("last-modified: {:?}", last_modified);
592    ///     }
593    ///     if let Some(blob_sequence_number) = response.blob_sequence_number()? {
594    ///         println!("x-ms-blob-sequence-number: {:?}", blob_sequence_number);
595    ///     }
596    ///     Ok(())
597    /// }
598    /// ```
599    ///
600    /// ### Available headers
601    /// * [`etag`()](crate::generated::models::PageBlobClientSetSequenceNumberResultHeaders::etag) - etag
602    /// * [`last_modified`()](crate::generated::models::PageBlobClientSetSequenceNumberResultHeaders::last_modified) - last-modified
603    /// * [`blob_sequence_number`()](crate::generated::models::PageBlobClientSetSequenceNumberResultHeaders::blob_sequence_number) - x-ms-blob-sequence-number
604    ///
605    /// [`PageBlobClientSetSequenceNumberResultHeaders`]: crate::generated::models::PageBlobClientSetSequenceNumberResultHeaders
606    #[tracing::function("Storage.Blob.PageBlobClient.setSequenceNumber")]
607    pub async fn set_sequence_number(
608        &self,
609        sequence_number_action: SequenceNumberActionType,
610        options: Option<PageBlobClientSetSequenceNumberOptions<'_>>,
611    ) -> Result<Response<PageBlobClientSetSequenceNumberResult, NoFormat>> {
612        let options = options.unwrap_or_default();
613        let ctx = options.method_options.context.to_borrowed();
614        let mut url = self.endpoint.clone();
615        let mut query_builder = url.query_builder();
616        query_builder.append_pair("comp", "properties");
617        if let Some(timeout) = options.timeout {
618            query_builder.set_pair("timeout", timeout.to_string());
619        }
620        query_builder.build();
621        let mut request = Request::new(url, Method::Put);
622        if let Some(if_match) = options.if_match.as_ref() {
623            request.insert_header("if-match", if_match.to_string());
624        }
625        if let Some(if_modified_since) = options.if_modified_since {
626            request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
627        }
628        if let Some(if_none_match) = options.if_none_match.as_ref() {
629            request.insert_header("if-none-match", if_none_match.to_string());
630        }
631        if let Some(if_unmodified_since) = options.if_unmodified_since {
632            request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
633        }
634        if let Some(blob_sequence_number) = options.blob_sequence_number {
635            request.insert_header(
636                "x-ms-blob-sequence-number",
637                blob_sequence_number.to_string(),
638            );
639        }
640        if let Some(if_tags) = options.if_tags.as_ref() {
641            request.insert_header("x-ms-if-tags", if_tags);
642        }
643        if let Some(lease_id) = options.lease_id.as_ref() {
644            request.insert_header("x-ms-lease-id", lease_id);
645        }
646        request.insert_header(
647            "x-ms-sequence-number-action",
648            sequence_number_action.to_string(),
649        );
650        request.insert_header("x-ms-version", &self.version);
651        let rsp = self
652            .pipeline
653            .send(
654                &ctx,
655                &mut request,
656                Some(PipelineSendOptions {
657                    check_success: CheckSuccessOptions {
658                        success_codes: &[200],
659                    },
660                    ..Default::default()
661                }),
662            )
663            .await?;
664        Ok(rsp.into())
665    }
666
667    /// Writes a range of pages to the specified page blob.
668    ///
669    /// # Arguments
670    ///
671    /// * `body` - The body of the request.
672    /// * `content_length` - The length of the request.
673    /// * `range` - Specifies the range of the blob to operate on.
674    /// * `options` - Optional parameters for the request.
675    ///
676    /// ## Response Headers
677    ///
678    /// The returned [`Response`](azure_core::http::Response) implements the [`PageBlobClientUploadPagesResultHeaders`] trait, which provides
679    /// access to response headers. For example:
680    ///
681    /// ```no_run
682    /// use azure_core::{Result, http::{Response, NoFormat}};
683    /// use azure_storage_blob::models::{PageBlobClientUploadPagesResult, PageBlobClientUploadPagesResultHeaders};
684    /// async fn example() -> Result<()> {
685    ///     let response: Response<PageBlobClientUploadPagesResult, NoFormat> = unimplemented!();
686    ///     // Access response headers
687    ///     if let Some(content_md5) = response.content_md5()? {
688    ///         println!("content-md5: {:?}", content_md5);
689    ///     }
690    ///     if let Some(etag) = response.etag()? {
691    ///         println!("etag: {:?}", etag);
692    ///     }
693    ///     if let Some(last_modified) = response.last_modified()? {
694    ///         println!("last-modified: {:?}", last_modified);
695    ///     }
696    ///     Ok(())
697    /// }
698    /// ```
699    ///
700    /// ### Available headers
701    /// * [`content_md5`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::content_md5) - content-md5
702    /// * [`etag`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::etag) - etag
703    /// * [`last_modified`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::last_modified) - last-modified
704    /// * [`blob_sequence_number`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::blob_sequence_number) - x-ms-blob-sequence-number
705    /// * [`content_crc64`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::content_crc64) - x-ms-content-crc64
706    /// * [`encryption_key_sha256`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::encryption_key_sha256) - x-ms-encryption-key-sha256
707    /// * [`encryption_scope`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::encryption_scope) - x-ms-encryption-scope
708    /// * [`is_server_encrypted`()](crate::generated::models::PageBlobClientUploadPagesResultHeaders::is_server_encrypted) - x-ms-request-server-encrypted
709    ///
710    /// [`PageBlobClientUploadPagesResultHeaders`]: crate::generated::models::PageBlobClientUploadPagesResultHeaders
711    #[tracing::function("Storage.Blob.PageBlobClient.uploadPages")]
712    pub async fn upload_pages(
713        &self,
714        body: RequestContent<Bytes, NoFormat>,
715        content_length: u64,
716        range: HttpRange,
717        options: Option<PageBlobClientUploadPagesOptions<'_>>,
718    ) -> Result<Response<PageBlobClientUploadPagesResult, NoFormat>> {
719        let options = options.unwrap_or_default();
720        let ctx = options.method_options.context.to_borrowed();
721        let mut url = self.endpoint.clone();
722        let mut query_builder = url.query_builder();
723        query_builder.append_pair("comp", "page");
724        if let Some(timeout) = options.timeout {
725            query_builder.set_pair("timeout", timeout.to_string());
726        }
727        query_builder.build();
728        let mut request = Request::new(url, Method::Put);
729        request.insert_header("content-length", content_length.to_string());
730        if let Some(transactional_content_md5) = options.transactional_content_md5 {
731            request.insert_header("content-md5", base64::encode(transactional_content_md5));
732        }
733        request.insert_header("content-type", "application/octet-stream");
734        if let Some(if_match) = options.if_match.as_ref() {
735            request.insert_header("if-match", if_match.to_string());
736        }
737        if let Some(if_modified_since) = options.if_modified_since {
738            request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
739        }
740        if let Some(if_none_match) = options.if_none_match.as_ref() {
741            request.insert_header("if-none-match", if_none_match.to_string());
742        }
743        if let Some(if_unmodified_since) = options.if_unmodified_since {
744            request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
745        }
746        request.insert_header("range", range.to_string());
747        if let Some(transactional_content_crc64) = options.transactional_content_crc64 {
748            request.insert_header(
749                "x-ms-content-crc64",
750                base64::encode(transactional_content_crc64),
751            );
752        }
753        if let Some(encryption_algorithm) = options.encryption_algorithm.as_ref() {
754            request.insert_header(
755                "x-ms-encryption-algorithm",
756                encryption_algorithm.to_string(),
757            );
758        }
759        if let Some(encryption_key) = options.encryption_key.as_ref() {
760            request.insert_header("x-ms-encryption-key", encryption_key);
761        }
762        if let Some(encryption_key_sha256) = options.encryption_key_sha256.as_ref() {
763            request.insert_header("x-ms-encryption-key-sha256", encryption_key_sha256);
764        }
765        if let Some(encryption_scope) = options.encryption_scope.as_ref() {
766            request.insert_header("x-ms-encryption-scope", encryption_scope);
767        }
768        if let Some(if_sequence_number_equal_to) = options.if_sequence_number_equal_to {
769            request.insert_header(
770                "x-ms-if-sequence-number-eq",
771                if_sequence_number_equal_to.to_string(),
772            );
773        }
774        if let Some(if_sequence_number_less_than_or_equal_to) =
775            options.if_sequence_number_less_than_or_equal_to
776        {
777            request.insert_header(
778                "x-ms-if-sequence-number-le",
779                if_sequence_number_less_than_or_equal_to.to_string(),
780            );
781        }
782        if let Some(if_sequence_number_less_than) = options.if_sequence_number_less_than {
783            request.insert_header(
784                "x-ms-if-sequence-number-lt",
785                if_sequence_number_less_than.to_string(),
786            );
787        }
788        if let Some(if_tags) = options.if_tags.as_ref() {
789            request.insert_header("x-ms-if-tags", if_tags);
790        }
791        if let Some(lease_id) = options.lease_id.as_ref() {
792            request.insert_header("x-ms-lease-id", lease_id);
793        }
794        request.insert_header("x-ms-page-write", "update");
795        request.insert_header("x-ms-version", &self.version);
796        request.set_body(body);
797        let rsp = self
798            .pipeline
799            .send(
800                &ctx,
801                &mut request,
802                Some(PipelineSendOptions {
803                    check_success: CheckSuccessOptions {
804                        success_codes: &[201],
805                    },
806                    ..Default::default()
807                }),
808            )
809            .await?;
810        Ok(rsp.into())
811    }
812
813    /// Writes a range of pages to the specified page blob where the contents are read from a URL.
814    ///
815    /// # Arguments
816    ///
817    /// * `source_url` - Specifies the URL of the source.
818    /// * `source_range` - Specifies the bytes of the source.
819    /// * `content_length` - The length of the request.
820    /// * `range` - Specifies the range of the blob to operate on.
821    /// * `options` - Optional parameters for the request.
822    ///
823    /// ## Response Headers
824    ///
825    /// The returned [`Response`](azure_core::http::Response) implements the [`PageBlobClientUploadPagesFromUrlResultHeaders`] trait, which provides
826    /// access to response headers. For example:
827    ///
828    /// ```no_run
829    /// use azure_core::{Result, http::{Response, NoFormat}};
830    /// use azure_storage_blob::models::{PageBlobClientUploadPagesFromUrlResult, PageBlobClientUploadPagesFromUrlResultHeaders};
831    /// async fn example() -> Result<()> {
832    ///     let response: Response<PageBlobClientUploadPagesFromUrlResult, NoFormat> = unimplemented!();
833    ///     // Access response headers
834    ///     if let Some(content_md5) = response.content_md5()? {
835    ///         println!("content-md5: {:?}", content_md5);
836    ///     }
837    ///     if let Some(etag) = response.etag()? {
838    ///         println!("etag: {:?}", etag);
839    ///     }
840    ///     if let Some(last_modified) = response.last_modified()? {
841    ///         println!("last-modified: {:?}", last_modified);
842    ///     }
843    ///     Ok(())
844    /// }
845    /// ```
846    ///
847    /// ### Available headers
848    /// * [`content_md5`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::content_md5) - content-md5
849    /// * [`etag`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::etag) - etag
850    /// * [`last_modified`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::last_modified) - last-modified
851    /// * [`blob_sequence_number`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::blob_sequence_number) - x-ms-blob-sequence-number
852    /// * [`content_crc64`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::content_crc64) - x-ms-content-crc64
853    /// * [`encryption_key_sha256`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::encryption_key_sha256) - x-ms-encryption-key-sha256
854    /// * [`encryption_scope`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::encryption_scope) - x-ms-encryption-scope
855    /// * [`is_server_encrypted`()](crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders::is_server_encrypted) - x-ms-request-server-encrypted
856    ///
857    /// [`PageBlobClientUploadPagesFromUrlResultHeaders`]: crate::generated::models::PageBlobClientUploadPagesFromUrlResultHeaders
858    #[tracing::function("Storage.Blob.PageBlobClient.uploadPagesFromUrl")]
859    pub async fn upload_pages_from_url(
860        &self,
861        source_url: String,
862        source_range: HttpRange,
863        content_length: u64,
864        range: HttpRange,
865        options: Option<PageBlobClientUploadPagesFromUrlOptions<'_>>,
866    ) -> Result<Response<PageBlobClientUploadPagesFromUrlResult, NoFormat>> {
867        let options = options.unwrap_or_default();
868        let ctx = options.method_options.context.to_borrowed();
869        let mut url = self.endpoint.clone();
870        let mut query_builder = url.query_builder();
871        query_builder.append_pair("comp", "page");
872        if let Some(timeout) = options.timeout {
873            query_builder.set_pair("timeout", timeout.to_string());
874        }
875        query_builder.build();
876        let mut request = Request::new(url, Method::Put);
877        request.insert_header("content-length", content_length.to_string());
878        if let Some(if_match) = options.if_match.as_ref() {
879            request.insert_header("if-match", if_match.to_string());
880        }
881        if let Some(if_modified_since) = options.if_modified_since {
882            request.insert_header("if-modified-since", to_rfc7231(&if_modified_since));
883        }
884        if let Some(if_none_match) = options.if_none_match.as_ref() {
885            request.insert_header("if-none-match", if_none_match.to_string());
886        }
887        if let Some(if_unmodified_since) = options.if_unmodified_since {
888            request.insert_header("if-unmodified-since", to_rfc7231(&if_unmodified_since));
889        }
890        request.insert_header("range", range.to_string());
891        request.insert_header("x-ms-copy-source", source_url);
892        if let Some(copy_source_authorization) = options.copy_source_authorization.as_ref() {
893            request.insert_header("x-ms-copy-source-authorization", copy_source_authorization);
894        }
895        if let Some(encryption_algorithm) = options.encryption_algorithm.as_ref() {
896            request.insert_header(
897                "x-ms-encryption-algorithm",
898                encryption_algorithm.to_string(),
899            );
900        }
901        if let Some(encryption_key) = options.encryption_key.as_ref() {
902            request.insert_header("x-ms-encryption-key", encryption_key);
903        }
904        if let Some(encryption_key_sha256) = options.encryption_key_sha256.as_ref() {
905            request.insert_header("x-ms-encryption-key-sha256", encryption_key_sha256);
906        }
907        if let Some(encryption_scope) = options.encryption_scope.as_ref() {
908            request.insert_header("x-ms-encryption-scope", encryption_scope);
909        }
910        if let Some(file_request_intent) = options.file_request_intent.as_ref() {
911            request.insert_header("x-ms-file-request-intent", file_request_intent.to_string());
912        }
913        if let Some(if_sequence_number_equal_to) = options.if_sequence_number_equal_to {
914            request.insert_header(
915                "x-ms-if-sequence-number-eq",
916                if_sequence_number_equal_to.to_string(),
917            );
918        }
919        if let Some(if_sequence_number_less_than_or_equal_to) =
920            options.if_sequence_number_less_than_or_equal_to
921        {
922            request.insert_header(
923                "x-ms-if-sequence-number-le",
924                if_sequence_number_less_than_or_equal_to.to_string(),
925            );
926        }
927        if let Some(if_sequence_number_less_than) = options.if_sequence_number_less_than {
928            request.insert_header(
929                "x-ms-if-sequence-number-lt",
930                if_sequence_number_less_than.to_string(),
931            );
932        }
933        if let Some(if_tags) = options.if_tags.as_ref() {
934            request.insert_header("x-ms-if-tags", if_tags);
935        }
936        if let Some(lease_id) = options.lease_id.as_ref() {
937            request.insert_header("x-ms-lease-id", lease_id);
938        }
939        request.insert_header("x-ms-page-write", "update");
940        if let Some(source_content_crc64) = options.source_content_crc64 {
941            request.insert_header(
942                "x-ms-source-content-crc64",
943                base64::encode(source_content_crc64),
944            );
945        }
946        if let Some(source_content_md5) = options.source_content_md5 {
947            request.insert_header(
948                "x-ms-source-content-md5",
949                base64::encode(source_content_md5),
950            );
951        }
952        if let Some(source_encryption_algorithm) = options.source_encryption_algorithm.as_ref() {
953            request.insert_header(
954                "x-ms-source-encryption-algorithm",
955                source_encryption_algorithm.to_string(),
956            );
957        }
958        if let Some(source_encryption_key) = options.source_encryption_key.as_ref() {
959            request.insert_header("x-ms-source-encryption-key", source_encryption_key);
960        }
961        if let Some(source_encryption_key_sha256) = options.source_encryption_key_sha256.as_ref() {
962            request.insert_header(
963                "x-ms-source-encryption-key-sha256",
964                source_encryption_key_sha256,
965            );
966        }
967        if let Some(source_if_match) = options.source_if_match.as_ref() {
968            request.insert_header("x-ms-source-if-match", source_if_match.to_string());
969        }
970        if let Some(source_if_modified_since) = options.source_if_modified_since {
971            request.insert_header(
972                "x-ms-source-if-modified-since",
973                to_rfc7231(&source_if_modified_since),
974            );
975        }
976        if let Some(source_if_none_match) = options.source_if_none_match.as_ref() {
977            request.insert_header(
978                "x-ms-source-if-none-match",
979                source_if_none_match.to_string(),
980            );
981        }
982        if let Some(source_if_unmodified_since) = options.source_if_unmodified_since {
983            request.insert_header(
984                "x-ms-source-if-unmodified-since",
985                to_rfc7231(&source_if_unmodified_since),
986            );
987        }
988        request.insert_header("x-ms-source-range", source_range.to_string());
989        request.insert_header("x-ms-version", &self.version);
990        let rsp = self
991            .pipeline
992            .send(
993                &ctx,
994                &mut request,
995                Some(PipelineSendOptions {
996                    check_success: CheckSuccessOptions {
997                        success_codes: &[201],
998                    },
999                    ..Default::default()
1000                }),
1001            )
1002            .await?;
1003        Ok(rsp.into())
1004    }
1005}
1006
1007/// Default value for [`PageBlobClientOptions::version`].
1008pub(crate) const DEFAULT_VERSION: &str = "2026-04-06";
1009
1010impl Default for PageBlobClientOptions {
1011    fn default() -> Self {
1012        Self {
1013            client_options: ClientOptions::default(),
1014            version: String::from(DEFAULT_VERSION),
1015        }
1016    }
1017}