Skip to main content

RawNumber

Struct RawNumber 

Source
pub struct RawNumber { /* private fields */ }
Expand description

A numeric table or data table cell with display text.

Slack reference.

Implementations§

Source§

impl RawNumber

Source

pub fn builder() -> RawNumberBuilder

Starts a builder with the documented model defaults.

Examples found in repository?
examples/api_checkpoint.rs (line 101)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let accordion = Accordion::new([AccordionSection::builder("Details")
12        .block(
13            SectionBlock::builder()
14                .text("Iterator composition")
15                .build()?,
16        )
17        .build()?])?;
18    let expanded = MessagePayload::builder("C0123456")
19        .blocks(accordion)
20        .build()?;
21    assert_eq!(expanded.blocks().map(<[Block]>::len), Some(1));
22    let option = SelectOption::builder()
23        .text("First option")
24        .value("first")
25        .build()?;
26    assert_eq!(option.value(), "first");
27    let section = SectionBlock::builder()
28        .text("Hello, Rust!")
29        .accessory(
30            ButtonElement::builder()
31                .text("Read more")
32                .action_id("read")
33                .build()?,
34        )
35        .block_id("hello")
36        .build()?;
37    let edited = section
38        .clone()
39        .into_builder()
40        .text(PlainText::new("Updated")?)
41        .build()?;
42    assert_ne!(edited, section);
43    let message = MessagePayload::builder("C0123456").block(section).build()?;
44    assert_eq!(message.blocks().map(<[Block]>::len), Some(1));
45    let encoded = serde_json::to_string(&message)?;
46    assert_eq!(serde_json::from_str::<MessagePayload>(&encoded)?, message);
47    let omitted = MessagePayload::try_from(json!({"channel":"C0123456"}))?;
48    assert_eq!(
49        serde_json::to_value(omitted.into_builder().build()?)?,
50        json!({"channel":"C0123456"})
51    );
52
53    let rich = RichTextBlock::builder()
54        .element(
55            RichTextList::builder()
56                .style(RichTextListStyle::Bullet)
57                .element(
58                    RichTextSection::builder()
59                        .element(
60                            RichTextText::new("Native ownership")?
61                                .into_builder()
62                                .style(RichTextStyle::new().bold(true))
63                                .build()?,
64                        )
65                        .build()?,
66                )
67                .build()?,
68        )
69        .build()?;
70    let table = TableBlock::builder()
71        .row([
72            TableCell::from(RawText::new("Heading")?),
73            rich.clone().into(),
74        ])
75        .row([TableCell::from(RawText::new("Ragged rows are valid")?)])
76        .build()?;
77    assert_eq!(table.rows()[1].len(), 1);
78    let pending = TaskCardBlock::builder()
79        .task_id("review")
80        .title("Review")
81        .status(TaskStatus::Pending)
82        .details(rich)
83        .build()?;
84    let error = MessagePayload::builder("C0123456")
85        .block(pending.clone())
86        .build()
87        .unwrap_err();
88    assert_eq!(error.category(), ErrorCategory::TypeMismatch);
89    assert_eq!(error.path(), "MessagePayload.blocks[0].status");
90    let plan = PlanBlock::builder()
91        .title("Release")
92        .task(pending)
93        .build()?;
94    let wire = serde_json::to_value(&plan)?;
95    assert!(wire["tasks"][0].get("type").is_none());
96    assert_eq!(PlanBlock::try_from(wire)?, plan);
97    let count = JsonNumber::from(9_007_199_254_740_993_u64);
98    assert_eq!(serde_json::to_string(&count)?, "9007199254740993");
99    let data = DataTableBlock::builder()
100        .caption("Exact counts")
101        .row([RawNumber::builder().value(0_i64).text("Count").build()?])
102        .row([RawNumber::builder()
103            .value(count)
104            .text("9007199254740993")
105            .build()?])
106        .build()?;
107    assert_eq!(data.rows().len(), 2);
108    assert!(PlainText::new("").is_err());
109    assert_eq!(
110        serde_json::to_value(MarkdownText::new("*native*")?)?["text"],
111        Value::String("*native*".into())
112    );
113    assert!(std::mem::size_of::<Block>() <= 32);
114    fn send_sync<T: Send + Sync>() {}
115    send_sync::<MessagePayload>();
116    println!("{encoded}");
117    Ok(())
118}
Source

pub fn into_builder(self) -> RawNumberBuilder

Moves every field into an editable builder, preserving explicit omissions.

Source

pub fn value(&self) -> &JsonNumber

Borrows or copies value. Sets the numeric value used for sorting.

Source

pub fn text(&self) -> &str

Borrows or copies text. Sets the formatted text displayed for the number, such as 1,234.5.

Source

pub fn extensions(&self) -> &Map<String, Value>

Borrows checked, unmodeled JSON extension fields.

Trait Implementations§

Source§

impl Clone for RawNumber

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RawNumber

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RawNumber

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<RawNumber> for TableCell

Source§

fn from(value: RawNumber) -> Self

Converts to this type from the input type.
Source§

impl From<RawNumber> for DataTableCell

Source§

fn from(value: RawNumber) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for RawNumber

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for RawNumber

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RawNumber

Source§

impl TryFrom<Value> for RawNumber

Source§

type Error = ValidationError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, ValidationError>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.