Ok,
So, even cargo check
only outputs the same error info as when cargo run
I cannot figure out where the expectation for a String comes from, when I clearly specify an Option in both the struct
and the new
function.
example:
error[E0308]: mismatched types
--> src/sofa_eater.rs:344:26
|
344 | Some(trans.deliveryInfo), //email_delivery_info
| ---- ^^^^^^^^^^^^^^^^^^ expected `String`, found `Option<String>`
| |
| arguments to this enum variant are incorrect
|
= note: expected struct `std::string::String`
found enum `std::option::Option<std::string::String>`
help: the type constructed contains `std::option::Option<std::string::String>` due to the type of the argument passed
--> src/sofa_eater.rs:344:21
|
344 | Some(trans.deliveryInfo), //email_delivery_info
| ^^^^^------------------^
| |
| this argument influences the type of `Some`
note: tuple variant defined here
--> /home/aaron/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:579:5
|
579 | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^^^
help: consider using `Option::expect` to unwrap the `std::option::Option<std::string::String>` value, panicking if the value is an `Option::None`
|
344 | Some(trans.deliveryInfo.expect("REASON")), //email_delivery_info
| +++++++++++++++++
error[E0308]: mismatched types
--> src/sofa_eater.rs:345:26
|
345 | Some(trans.smsIdTwilio), //sms_id_twilio
| ---- ^^^^^^^^^^^^^^^^^ expected `String`, found `Option<String>`
| |
| arguments to this enum variant are incorrect
|
= note: expected struct `std::string::String`
found enum `std::option::Option<std::string::String>`
help: the type constructed contains `std::option::Option<std::string::String>` due to the type of the argument passed
--> src/sofa_eater.rs:345:21
|
345 | Some(trans.smsIdTwilio), //sms_id_twilio
| ^^^^^-----------------^
| |
| this argument influences the type of `Some`
note: tuple variant defined here
--> /home/aaron/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:579:5
|
579 | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^^^
help: consider using `Option::expect` to unwrap the `std::option::Option<std::string::String>` value, panicking if the value is an `Option::None`
|
345 | Some(trans.smsIdTwilio.expect("REASON")), //sms_id_twilio
| +++++++++++++++++
error[E0308]: mismatched types
--> src/sofa_eater.rs:346:26
|
346 | Some(trans.sms_twilio_date_updated),
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Option<String>`
| |
| arguments to this enum variant are incorrect
|
= note: expected struct `std::string::String`
found enum `std::option::Option<std::string::String>`
help: the type constructed contains `std::option::Option<std::string::String>` due to the type of the argument passed
--> src/sofa_eater.rs:346:21
|
346 | Some(trans.sms_twilio_date_updated),
| ^^^^^-----------------------------^
| |
| this argument influences the type of `Some`
note: tuple variant defined here
--> /home/aaron/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:579:5
|
579 | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^^^
help: consider using `Option::expect` to unwrap the `std::option::Option<std::string::String>` value, panicking if the value is an `Option::None`
|
346 | Some(trans.sms_twilio_date_updated.expect("REASON")),
| +++++++++++++++++
and the struct that is being instantiated, which should specify the expected part, right?
pub struct OldTransaction {
pub id: i64,
pub sender: i32,
pub chosen_card: i64,
pub datetime_sent: Option<String>,
pub rcvr: String,
pub rsvp_answer: Option<String>,
pub rsvp_comments: Option<String>,
pub reply_to_sender: Option<String>,
pub email_delivery_info: Option<String>,
pub sms_id_twilio: Option<String>,
pub sms_twilio_date_updated: Option<String>,
pub public_id: String,
}
pub async fn new ( sender: i32,chosen_card: i64,datetime_sent: Option<String>,rcvr: String,rsvp_answer: Option<String>,rsvp_comments: Option<String>,reply_to_sender: Option<String>,email_delivery_info: Option<String>,sms_id_twilio: Option<String>,sms_twilio_date_updated: Option<String>,public_id: String ) -> Result<i64, sqlx::Error> {
let rec = sqlx::query!(
r#"
INSERT INTO old_transaction (sender,chosen_card,datetime_sent,rcvr,rsvp_answer,rsvp_comments,reply_to_sender,email_delivery_info,sms_id_twilio,sms_twilio_date_updated,public_id)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)
ON CONFLICT DO NOTHING
RETURNING id
"#,sender,chosen_card,datetime_sent,rcvr,rsvp_answer,rsvp_comments,reply_to_sender,email_delivery_info,sms_id_twilio,sms_twilio_date_updated,public_id)
.fetch_one(get_db_pool())
.await?;
Ok(rec.id)
}
when calling this function and instantiating this struct
let new_old_transaction = crate::models::old_transaction::OldTransaction::new (
owner, //sender
new_card_id, //chosen_card
Some(trans.timeUtc ), //datetime_sent
trans.whichRecipient, //rcvr
trans.rsvpAnswer, //rsvp_answer
trans.rsvpComments, //rsvp_comments
trans.reply, //reply_to_sender
Some(trans.deliveryInfo), //email_delivery_info
Some(trans.smsIdTwilio), //sms_id_twilio
Some(trans.sms_twilio_date_updated),
trans._id, //public_id
).await.unwrap();
I would love to know where the compiler got the notion that it wanted a String...