pub struct Form<'a> { /* private fields */ }Expand description
A result element, described but not yet built.
use bumpalo::Bump;
use xsd_schema::compose::{AttrValue, Composer, Content, Form, Name};
use xsd_schema::document::SerializeOptions;
use xsd_schema::namespace::NameTable;
let arena = Bump::new();
let names = NameTable::new();
let c = Composer::new(&arena, &names);
let mut title = Form::new(Name::local("title"));
title.push(Content::Text("One".to_string()));
let mut book = Form::new(Name::local("book"));
book.attr(Name::local("id"), AttrValue::text("b1"));
book.push(Content::Element(title));
let doc = c.build(book)?;
assert_eq!(
doc.to_xml(&SerializeOptions::default())?,
r#"<book id="b1"><title>One</title></book>"#,
);Implementations§
Source§impl<'a> Form<'a>
impl<'a> Form<'a>
Sourcepub fn new(name: Name) -> Self
pub fn new(name: Name) -> Self
An element with no declarations, attributes or content.
use xsd_schema::compose::{Form, Name};
let form = Form::new(Name::local("result"));
assert_eq!(form.name().local_name(), "result");
assert!(form.content().is_empty());Sourcepub fn declare(&mut self, prefix: &str, uri: &str) -> &mut Self
pub fn declare(&mut self, prefix: &str, uri: &str) -> &mut Self
Declares a namespace on this element, in scope for it and its descendants.
An empty prefix declares the default namespace; an empty prefix with an empty URI undeclares it. The declaration shadows the composer’s namespace table for this subtree, and is dropped from the output only when it is redundant.
use bumpalo::Bump;
use xsd_schema::compose::{Composer, Form, Name};
use xsd_schema::document::SerializeOptions;
use xsd_schema::namespace::NameTable;
let arena = Bump::new();
let names = NameTable::new();
let c = Composer::new(&arena, &names);
let mut form = Form::new(Name::prefixed("p", "root"));
form.declare("p", "urn:x");
assert_eq!(
c.build(form)?.to_xml(&SerializeOptions::default())?,
r#"<p:root xmlns:p="urn:x"/>"#,
);Sourcepub fn attr(&mut self, name: Name, value: AttrValue<'a>) -> &mut Self
pub fn attr(&mut self, name: Name, value: AttrValue<'a>) -> &mut Self
Adds an attribute.
Attributes are written in the order they are added. Two attributes with the same expanded name are a duplicate, and the later one wins.
use xsd_schema::compose::{AttrValue, Form, Name};
let mut form = Form::new(Name::local("book"));
form.attr(Name::local("id"), AttrValue::text("b1"))
.attr(Name::local("year"), AttrValue::text(1999));
assert_eq!(form.attributes().len(), 2);Sourcepub fn push(&mut self, content: Content<'a>) -> &mut Self
pub fn push(&mut self, content: Content<'a>) -> &mut Self
Appends one content item.
use xsd_schema::compose::{Content, Form, IntoContent, Name};
let mut form = Form::new(Name::local("p"));
form.push(Content::Text("a".to_string()))
.push("b".into_content());
assert_eq!(form.content().len(), 2);Sourcepub fn name(&self) -> &Name
pub fn name(&self) -> &Name
The element’s name.
use xsd_schema::compose::{Form, Name};
let form = Form::new(Name::prefixed("p", "root"));
assert_eq!(form.name().to_string(), "p:root");Sourcepub fn declarations(&self) -> &[(String, String)]
pub fn declarations(&self) -> &[(String, String)]
The namespace declarations the author asked for, in order.
use xsd_schema::compose::{Form, Name};
let mut form = Form::new(Name::local("root"));
form.declare("p", "urn:x");
assert_eq!(form.declarations(), [("p".to_string(), "urn:x".to_string())]);Sourcepub fn attributes(&self) -> &[(Name, AttrValue<'a>)]
pub fn attributes(&self) -> &[(Name, AttrValue<'a>)]
The attributes, in order.
use xsd_schema::compose::{AttrValue, Form, Name};
let mut form = Form::new(Name::local("book"));
form.attr(Name::local("id"), AttrValue::text("b1"));
assert_eq!(form.attributes()[0].0.local_name(), "id");Trait Implementations§
Source§impl<'a> IntoContent<'a> for Form<'a>
impl<'a> IntoContent<'a> for Form<'a>
Source§fn into_content(self) -> Content<'a>
fn into_content(self) -> Content<'a>
Converts
self into one content item.Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Form<'a>
impl<'a> !Send for Form<'a>
impl<'a> !Sync for Form<'a>
impl<'a> !UnwindSafe for Form<'a>
impl<'a> Forget for Form<'a>
impl<'a> Freeze for Form<'a>where
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<(String, String)>: Freeze,
PhantomData<(Name, AttrValue<'a>)>: Freeze,
PhantomData<Content<'a>>: Freeze,
impl<'a> Move for Form<'a>
impl<'a> Unpin for Form<'a>
impl<'a> UnsafeUnpin for Form<'a>where
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<(String, String)>: UnsafeUnpin,
PhantomData<(Name, AttrValue<'a>)>: UnsafeUnpin,
PhantomData<Content<'a>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more