Skip to content

Commit

Permalink
add default constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
TvoroG committed Feb 18, 2021
1 parent dc8d4cc commit d2d71d6
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/native/v1_2/request/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,29 @@ pub struct Asset {
#[serde(skip_serializing_if = "Option::is_none")]
pub ext: Option<serde_utils::Ext>,
}

impl Asset {
pub fn new(id: u32, required: bool) -> Self {
Asset {
id,
required,
title: None,
image: None,
video: None,
data: None,
ext: None,
}
}

pub fn new_title(id: u32, required: bool, title: Title) -> Self {
let mut asset = Asset::new(id, required);
asset.title = Some(title);
asset
}

pub fn new_image(id: u32, required: bool, image: Image) -> Self {
let mut asset = Asset::new(id, required);
asset.image = Some(image);
asset
}
}
8 changes: 7 additions & 1 deletion src/native/v1_2/request/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde_utils;

use super::image_type::ImageTypeID;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct Image {
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub type_id: Option<ImageTypeID>,
Expand All @@ -25,3 +25,9 @@ pub struct Image {
#[serde(skip_serializing_if = "Option::is_none")]
pub ext: Option<serde_utils::Ext>,
}

impl Image {
pub fn new() -> Self {
Default::default()
}
}
8 changes: 7 additions & 1 deletion src/native/v1_2/request/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::context_type::ContextTypeID;
use super::context_sub_type::ContextSubTypeID;
use super::asset::Asset;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct Request {
#[serde(rename = "ver", skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
Expand Down Expand Up @@ -39,3 +39,9 @@ pub struct Request {
#[serde(skip_serializing_if = "Option::is_none")]
pub ext: Option<serde_utils::Ext>,
}

impl Request {
pub fn new() -> Self {
Default::default()
}
}
9 changes: 9 additions & 0 deletions src/native/v1_2/request/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ pub struct Title {
#[serde(skip_serializing_if = "Option::is_none")]
pub ext: Option<serde_utils::Ext>,
}

impl Title {
pub fn new(length: u32) -> Self {
Title {
length,
ext: None,
}
}
}
22 changes: 22 additions & 0 deletions src/v2_5/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ pub struct Imp {
pub ext: Option<serde_utils::Ext>,
}

impl Imp {
pub fn new(id: String) -> Self {
Imp {
id,
metric: vec![],
banner: None,
video: None,
audio: None,
native: None,
pmp: None,
display_manager: None,
display_manager_ver: None,
interstitial: None,
tag_id: None,
bid_floor: None,
bid_floor_cur: None,
secure: None,
ext: None,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
12 changes: 12 additions & 0 deletions src/v2_5/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ pub struct Native {
#[serde(skip_serializing_if = "Option::is_none")]
pub ext: Option<serde_utils::Ext>,
}

impl Native {
pub fn new(request: String) -> Self {
Native {
request,
version: None,
api: vec![],
blocked_attrs: vec![],
ext: None,
}
}
}

0 comments on commit d2d71d6

Please sign in to comment.