mirror of
https://github.com/Noratrieb/terustform.git
synced 2026-01-14 16:35:11 +01:00
Derive macro getting works
This commit is contained in:
parent
63bd32c3cd
commit
7d28815065
9 changed files with 245 additions and 41 deletions
|
|
@ -6,6 +6,5 @@ edition = "2021"
|
|||
[dependencies]
|
||||
eyre = "0.6.12"
|
||||
terustform = { path = "../terustform" }
|
||||
terustform-macros = { path = "../terustform-macros" }
|
||||
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ use terustform::{
|
|||
framework::{
|
||||
datasource::{self, DataSource},
|
||||
provider::Provider,
|
||||
value::StringValue,
|
||||
DResult,
|
||||
AttrPath, DResult, Diagnostics, StringValue, ValueModel,
|
||||
},
|
||||
values::{Value, ValueKind},
|
||||
};
|
||||
|
|
@ -29,11 +28,6 @@ impl Provider for ExampleProvider {
|
|||
|
||||
struct ExampleDataSource {}
|
||||
|
||||
#[derive(terustform_macros::DataSourceModel)]
|
||||
struct _ExampleDataSourceModel {
|
||||
name: StringValue,
|
||||
}
|
||||
|
||||
impl DataSource for ExampleDataSource {
|
||||
fn name(&self, provider_name: &str) -> String {
|
||||
format!("{provider_name}_kitty")
|
||||
|
|
@ -72,20 +66,20 @@ impl DataSource for ExampleDataSource {
|
|||
}
|
||||
|
||||
fn read(&self, config: Value) -> DResult<Value> {
|
||||
let name = match config {
|
||||
Value::Known(ValueKind::Object(mut obj)) => obj.remove("name").unwrap(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let name_str = match &name {
|
||||
Value::Known(ValueKind::String(s)) => s.clone(),
|
||||
_ => unreachable!(),
|
||||
let model = ExampleDataSourceModel::from_value(config, &AttrPath::root())?;
|
||||
|
||||
let StringValue::Known(name_str) = &model.name else {
|
||||
return Err(Diagnostics::error_string(
|
||||
"model name must be known".to_owned(),
|
||||
));
|
||||
};
|
||||
let meow = format!("mrrrrr i am {name_str}");
|
||||
|
||||
Ok(Value::Known(ValueKind::Object(BTreeMap::from([
|
||||
("name".to_owned(), name),
|
||||
("name".to_owned(), model.name.to_value()),
|
||||
(
|
||||
"meow".to_owned(),
|
||||
Value::Known(ValueKind::String(format!("mrrrrr i am {name_str}"))),
|
||||
Value::Known(ValueKind::String(meow)),
|
||||
),
|
||||
(
|
||||
"id".to_owned(),
|
||||
|
|
@ -94,3 +88,10 @@ impl DataSource for ExampleDataSource {
|
|||
]))))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(terustform::DataSourceModel)]
|
||||
struct ExampleDataSourceModel {
|
||||
name: StringValue,
|
||||
meow: StringValue,
|
||||
id: StringValue,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue