Skip to content

Commit

Permalink
refactor: Drop manual default implementations
Browse files Browse the repository at this point in the history
in favor of the corresponding macro.

(cherry picked from commit 967d100042c363b1788fe9439f74901cabd83363)
  • Loading branch information
AiyionPrime committed Jul 23, 2024
1 parent 9698fa0 commit dad768e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 60 deletions.
10 changes: 1 addition & 9 deletions lib/src/server/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,12 @@ pub enum ServerUserIdentityToken {
Invalid(ExtensionObject),
}

#[derive(Default)]
pub struct SessionManager {
pub sessions: HashMap<NodeId, Arc<RwLock<Session>>>,
pub sessions_terminated: bool,
}

impl Default for SessionManager {
fn default() -> Self {
Self {
sessions: HashMap::new(),
sessions_terminated: false,
}
}
}

impl SessionManager {
pub fn len(&self) -> usize {
self.sessions.len()
Expand Down
11 changes: 1 addition & 10 deletions lib/src/server/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,13 @@ use super::{

/// This object tracks session diagnostics for exposure through the address space
#[derive(Default)]
pub(crate) struct SessionDiagnostics {
total_request_count: u32,
unauthorized_request_count: u32,
service_counters: HashMap<&'static str, ServiceCounterDataType>,
}

impl Default for SessionDiagnostics {
fn default() -> Self {
Self {
total_request_count: 0,
unauthorized_request_count: 0,
service_counters: HashMap::new(),
}
}
}

impl SessionDiagnostics {
/// Registers a session object
pub(crate) fn register_session(&self, session: &Session, address_space: &mut AddressSpace) {
Expand Down
33 changes: 2 additions & 31 deletions lib/src/types/service_types/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use crate::types::{
enums::DeadbandType, AnonymousIdentityToken, ApplicationDescription, ApplicationType,
Argument, CallMethodRequest, DataChangeFilter, DataChangeTrigger, DataSetFieldFlags,
EndpointDescription, MessageSecurityMode, MonitoredItemCreateRequest, MonitoringMode,
MonitoringParameters, ReadValueId, ServerDiagnosticsSummaryDataType,
ServiceCounterDataType, ServiceFault, SignatureData, UserNameIdentityToken,
UserTokenPolicy, UserTokenType,
MonitoringParameters, ReadValueId, ServiceCounterDataType, ServiceFault, SignatureData,
UserNameIdentityToken, UserTokenPolicy, UserTokenType,
},
status_codes::StatusCode,
string::UAString,
Expand Down Expand Up @@ -346,25 +345,6 @@ impl Into<CallMethodRequest> for (NodeId, NodeId, Option<Vec<Variant>>) {
}
}

impl Default for ServerDiagnosticsSummaryDataType {
fn default() -> Self {
ServerDiagnosticsSummaryDataType {
server_view_count: 0,
current_session_count: 0,
cumulated_session_count: 0,
security_rejected_session_count: 0,
rejected_session_count: 0,
session_timeout_count: 0,
session_abort_count: 0,
current_subscription_count: 0,
cumulated_subscription_count: 0,
publishing_interval_count: 0,
security_rejected_requests_count: 0,
rejected_requests_count: 0,
}
}
}

impl<'a> From<&'a str> for EndpointDescription {
fn from(v: &'a str) -> Self {
EndpointDescription::from((
Expand Down Expand Up @@ -477,15 +457,6 @@ impl From<(&str, DataTypeId)> for Argument {
}
}

impl Default for ServiceCounterDataType {
fn default() -> Self {
Self {
total_count: 0,
error_count: 0,
}
}
}

impl ServiceCounterDataType {
pub fn success(&mut self) {
self.total_count += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::types::{
};
use std::io::{Read, Write};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
#[serde(rename_all = "PascalCase")]
pub struct ServerDiagnosticsSummaryDataType {
pub server_view_count: u32,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/types/service_types/service_counter_data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::types::{
};
use std::io::{Read, Write};

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ServiceCounterDataType {
pub total_count: u32,
pub error_count: u32,
Expand Down
9 changes: 2 additions & 7 deletions lib/src/types/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use crate::types::{
///
/// As variants may be passed around a lot on the stack, Boxes are used for more complex types to
/// keep the size of this type down a bit, especially when used in arrays.
#[derive(PartialEq, Debug, Clone)]
#[derive(PartialEq, Debug, Clone, Default)]
pub enum Variant {
/// Empty type has no value. It is equivalent to a Null value (part 6 5.1.6)
#[default]
Empty,
/// Boolean
Boolean(bool),
Expand Down Expand Up @@ -669,12 +670,6 @@ impl BinaryEncoder<Variant> for Variant {
}
}

impl Default for Variant {
fn default() -> Self {
Variant::Empty
}
}

/// This implementation is mainly for debugging / convenience purposes, to eliminate some of the
/// noise in common types from using the Debug trait.
impl fmt::Display for Variant {
Expand Down
2 changes: 1 addition & 1 deletion tools/schema/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function makeImportLookupMap(import_map) {
}

// Types that will be marked as Default constructable
const DEFAULT_TYPES = ["ReadValueId", ];
const DEFAULT_TYPES = ["ReadValueId", "ServerDiagnosticsSummaryDataType", "ServiceCounterDataType"];

// Types that will be marked as JSON serializable. Serialization is for pubsub, and debugging purposes
const JSON_SERIALIZED_TYPES = [
Expand Down

0 comments on commit dad768e

Please sign in to comment.