Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OPOSSUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
phelix
rust
OPOSSUM
Commits
d80d9dd7
Commit
d80d9dd7
authored
1 year ago
by
Udo Eisenbarth
Browse files
Options
Downloads
Patches
Plain Diff
Add OpticPort
parent
a4b7ea9b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib.rs
+1
-0
1 addition, 0 deletions
src/lib.rs
src/optic_port.rs
+87
-0
87 additions, 0 deletions
src/optic_port.rs
with
88 additions
and
0 deletions
src/lib.rs
+
1
−
0
View file @
d80d9dd7
...
...
@@ -4,6 +4,7 @@
pub
mod
optic_scenery
;
/// The basic structure representing an optical element
pub
mod
optic_node
;
pub
mod
optic_port
;
pub
mod
nodes
;
...
...
This diff is collapsed.
Click to expand it.
src/optic_port.rs
0 → 100644
+
87
−
0
View file @
d80d9dd7
#[derive(Debug,
PartialEq,
Clone)]
pub
enum
OpticPortDirection
{
Incoming
,
Outgoing
,
}
impl
OpticPortDirection
{
fn
invert
(
self
)
->
OpticPortDirection
{
if
self
==
OpticPortDirection
::
Incoming
{
OpticPortDirection
::
Outgoing
}
else
{
OpticPortDirection
::
Incoming
}
}
}
#[derive(Debug)]
pub
struct
OpticPort
{
name
:
String
,
direction
:
OpticPortDirection
,
}
impl
OpticPort
{
pub
fn
new
(
name
:
&
str
,
direction
:
OpticPortDirection
)
->
Self
{
Self
{
name
:
name
.into
(),
direction
:
direction
}
}
pub
fn
set_name
(
&
mut
self
,
name
:
&
str
)
{
self
.name
=
name
.into
();
}
pub
fn
name
(
&
self
)
->
&
str
{
self
.name
.as_ref
()
}
pub
fn
set_direction
(
&
mut
self
,
direction
:
OpticPortDirection
)
{
self
.direction
=
direction
;
}
pub
fn
direction
(
&
self
)
->
&
OpticPortDirection
{
&
self
.direction
}
pub
fn
invert
(
&
mut
self
)
{
self
.direction
=
self
.direction
.clone
()
.invert
();
}
}
#[cfg(test)]
mod
test
{
use
crate
::
optic_port
::{
OpticPort
,
OpticPortDirection
};
#[test]
fn
new
()
{
let
port
=
OpticPort
::
new
(
"Test"
,
OpticPortDirection
::
Incoming
);
assert_eq!
(
port
.name
,
"Test"
);
assert_eq!
(
port
.direction
,
OpticPortDirection
::
Incoming
);
}
#[test]
fn
set_name
()
{
let
mut
port
=
OpticPort
::
new
(
"Test"
,
OpticPortDirection
::
Incoming
);
port
.set_name
(
"Test2"
);
assert_eq!
(
port
.name
,
"Test2"
);
assert_eq!
(
port
.direction
,
OpticPortDirection
::
Incoming
);
}
#[test]
fn
name
()
{
let
port
=
OpticPort
::
new
(
"Test"
,
OpticPortDirection
::
Incoming
);
assert_eq!
(
port
.name
(),
"Test"
);
}
#[test]
fn
set_direction
()
{
let
mut
port
=
OpticPort
::
new
(
"Test"
,
OpticPortDirection
::
Incoming
);
port
.set_direction
(
OpticPortDirection
::
Outgoing
);
assert_eq!
(
port
.name
,
"Test"
);
assert_eq!
(
port
.direction
,
OpticPortDirection
::
Outgoing
);
}
#[test]
fn
direction
()
{
let
port
=
OpticPort
::
new
(
"Test"
,
OpticPortDirection
::
Incoming
);
assert_eq!
(
port
.direction
(),
&
OpticPortDirection
::
Incoming
);
}
#[test]
fn
invert
()
{
let
mut
port
=
OpticPort
::
new
(
"Test"
,
OpticPortDirection
::
Incoming
);
port
.invert
();
assert_eq!
(
port
.direction
,
OpticPortDirection
::
Outgoing
);
assert_eq!
(
port
.name
,
"Test"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment