Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
ink
Commits
f548ea51
Commit
f548ea51
authored
Jan 09, 2019
by
Hero Bird
Browse files
[examples/Subpeep] Move Subpeep::{recent_peeps, recent_user_peeps} to tests
parent
c11e4031
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/subpeep/src/lib.rs
View file @
f548ea51
...
...
@@ -101,42 +101,6 @@ impl Subpeep {
}
}
/// Returns all recent global posts as vector.
pub
(
crate
)
fn
recent_peeps
(
&
self
,
amount
:
usize
)
->
Vec
<
Peep
>
{
self
.peeps
.iter
()
.rev
()
.take
(
amount
)
.cloned
()
.collect
()
}
/// Returns the `n` most recent peeps of the given user.
///
/// Returns `None` if the user does not exist.
pub
(
crate
)
fn
recent_user_peeps
(
&
self
,
amount
:
usize
,
username
:
&
str
,
)
->
Option
<
Vec
<
Peep
>>
{
self
.users
.get
(
username
)
.map
(|
user
|
{
user
.peeps
.iter
()
.rev
()
.take
(
amount
)
.cloned
()
.map
(|
message
|
{
Peep
::
new
(
username
.into
(),
message
)
})
.collect
()
})
}
/// Posts a message to the global channel.
///
/// Will only ever store the latest 10 messages in the channel at most.
...
...
examples/subpeep/src/tests.rs
View file @
f548ea51
use
super
::
*
;
use
pdsl_core
::
memory
::
vec
::
Vec
;
impl
Subpeep
{
/// Returns all recent global posts as vector.
pub
(
crate
)
fn
recent_peeps
(
&
self
,
amount
:
usize
)
->
Vec
<
Peep
>
{
self
.peeps
.iter
()
.rev
()
.take
(
amount
)
.cloned
()
.collect
()
}
/// Returns the `n` most recent peeps of the given user.
///
/// Returns `None` if the user does not exist.
pub
(
crate
)
fn
recent_user_peeps
(
&
self
,
amount
:
usize
,
username
:
&
str
,
)
->
Option
<
Vec
<
Peep
>>
{
self
.users
.get
(
username
)
.map
(|
user
|
{
user
.peeps
.iter
()
.rev
()
.take
(
amount
)
.cloned
()
.map
(|
message
|
{
Peep
::
new
(
username
.into
(),
message
)
})
.collect
()
})
}
}
#[macro_use]
use
pdsl_core
::
memory
::
vec
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment