Skip to content

Default trait for variables #477

Open
@danielboros1990

Description

@danielboros1990

Hi guys,

is it possible to use Default trait instead of writing None for nullable values.

// current solutions
set: StreamsSetInput {
                        id: None,
                        user_id: None,
                        stream_id: None,
                        is_online: None,
                        live_ms: Some(stream.live_ms.unwrap().to_string()),
                        frames: Some(stream.frames.unwrap().to_string()),
                        send_bytes: Some(stream.send_bytes.unwrap().to_string()),
                        recv_bytes: Some(stream.recv_bytes.unwrap().to_string()),
                        video_codec: Some(stream.video.as_ref().unwrap().codec.clone().unwrap()),
                        video_profile: Some(
                            stream.video.as_ref().unwrap().profile.clone().unwrap(),
                        ),
                        video_level: Some(stream.video.as_ref().unwrap().level.clone().unwrap()),
                        video_width: Some(stream.video.as_ref().unwrap().width.unwrap().into()),
                        video_height: Some(stream.video.as_ref().unwrap().height.unwrap().into()),
                        audio_codec: Some(stream.audio.as_ref().unwrap().codec.clone()),
                        audio_sample_rate: Some(stream.audio.as_ref().unwrap().sample_rate.into()),
                        audio_channel: Some(stream.audio.as_ref().unwrap().channel.into()),
                        audio_profile: Some(stream.audio.as_ref().unwrap().profile.clone()),
                        created_at: None,
                        updated_at: None,
                    },

// expected solutions
set: StreamsSetInput {
                        live_ms: Some(stream.live_ms.unwrap().to_string()),
                        frames: Some(stream.frames.unwrap().to_string()),
                        send_bytes: Some(stream.send_bytes.unwrap().to_string()),
                        recv_bytes: Some(stream.recv_bytes.unwrap().to_string()),
                        video_codec: Some(stream.video.as_ref().unwrap().codec.clone().unwrap()),
                        video_profile: Some(
                            stream.video.as_ref().unwrap().profile.clone().unwrap(),
                        ),
                        video_level: Some(stream.video.as_ref().unwrap().level.clone().unwrap()),
                        video_width: Some(stream.video.as_ref().unwrap().width.unwrap().into()),
                        video_height: Some(stream.video.as_ref().unwrap().height.unwrap().into()),
                        audio_codec: Some(stream.audio.as_ref().unwrap().codec.clone()),
                        audio_sample_rate: Some(stream.audio.as_ref().unwrap().sample_rate.into()),
                        audio_channel: Some(stream.audio.as_ref().unwrap().channel.into()),
                        audio_profile: Some(stream.audio.as_ref().unwrap().profile.clone()),
                        ..Default::default()
                    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions