Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
14cb4be6
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
14cb4be6
编写于
2月 07, 2014
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #12083 : bjz/rust/semver, r=huonw
上级
36f1b38f
aa829c29
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
20 deletion
+56
-20
src/libsemver/lib.rs
src/libsemver/lib.rs
+56
-20
未找到文件。
src/libsemver/lib.rs
浏览文件 @
14cb4be6
...
...
@@ -35,6 +35,7 @@
use
std
::
char
;
use
std
::
cmp
;
use
std
::
fmt
;
use
std
::
option
::{
Option
,
Some
,
None
};
use
std
::
to_str
::
ToStr
;
...
...
@@ -59,13 +60,20 @@ fn lt(&self, other: &Identifier) -> bool {
}
}
impl
fmt
::
Show
for
Identifier
{
#[inline]
fn
fmt
(
version
:
&
Identifier
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
match
*
version
{
Numeric
(
ref
n
)
=>
fmt
::
Show
::
fmt
(
n
,
f
),
AlphaNumeric
(
ref
s
)
=>
fmt
::
Show
::
fmt
(
s
,
f
)
}
}
}
impl
ToStr
for
Identifier
{
#[inline]
fn
to_str
(
&
self
)
->
~
str
{
match
self
{
&
Numeric
(
n
)
=>
n
.to_str
(),
&
AlphaNumeric
(
ref
s
)
=>
s
.to_str
()
}
format!
(
"{}"
,
*
self
)
}
}
...
...
@@ -74,33 +82,45 @@ fn to_str(&self) -> ~str {
#[deriving(Clone,
Eq)]
pub
struct
Version
{
/// The major version, to be incremented on incompatible changes.
priv
major
:
uint
,
major
:
uint
,
/// The minor version, to be incremented when functionality is added in a
/// backwards-compatible manner.
priv
minor
:
uint
,
minor
:
uint
,
/// The patch version, to be incremented when backwards-compatible bug
/// fixes are made.
p
riv
p
atch
:
uint
,
patch
:
uint
,
/// The pre-release version identifier, if one exists.
pr
iv
pr
e
:
~
[
Identifier
],
pre
:
~
[
Identifier
],
/// The build metadata, ignored when determining version precedence.
priv
build
:
~
[
Identifier
],
build
:
~
[
Identifier
],
}
impl
fmt
::
Show
for
Version
{
#[inline]
fn
fmt
(
version
:
&
Version
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
if_ok!
(
write!
(
f
.buf
,
"{}.{}.{}"
,
version
.major
,
version
.minor
,
version
.patch
))
if
!
version
.pre
.is_empty
()
{
if_ok!
(
write!
(
f
.buf
,
"-"
));
for
(
i
,
x
)
in
version
.pre
.iter
()
.enumerate
()
{
if
i
!=
0
{
if_ok!
(
write!
(
f
.buf
,
"."
))
};
if_ok!
(
fmt
::
Show
::
fmt
(
x
,
f
));
}
}
if
!
version
.build
.is_empty
()
{
if_ok!
(
write!
(
f
.buf
,
"+"
));
for
(
i
,
x
)
in
version
.build
.iter
()
.enumerate
()
{
if
i
!=
0
{
if_ok!
(
write!
(
f
.buf
,
"."
))
};
if_ok!
(
fmt
::
Show
::
fmt
(
x
,
f
));
}
}
Ok
(())
}
}
impl
ToStr
for
Version
{
#[inline]
fn
to_str
(
&
self
)
->
~
str
{
let
s
=
format!
(
"{}.{}.{}"
,
self
.major
,
self
.minor
,
self
.patch
);
let
s
=
if
self
.pre
.is_empty
()
{
s
}
else
{
format!
(
"{}-{}"
,
s
,
self
.pre
.map
(|
i
|
i
.to_str
())
.connect
(
"."
))
};
if
self
.build
.is_empty
()
{
s
}
else
{
format!
(
"{}+{}"
,
s
,
self
.build
.map
(|
i
|
i
.to_str
())
.connect
(
"."
))
}
format!
(
"{}"
,
*
self
)
}
}
...
...
@@ -365,6 +385,22 @@ fn test_ne() {
assert
!
(
parse
(
"1.2.3+23"
)
!=
parse
(
"1.2.3+42"
));
}
#[test]
fn
test_show
()
{
assert_eq!
(
format!
(
"{}"
,
parse
(
"1.2.3"
)
.unwrap
()),
~
"1.2.3"
);
assert_eq!
(
format!
(
"{}"
,
parse
(
"1.2.3-alpha1"
)
.unwrap
()),
~
"1.2.3-alpha1"
);
assert_eq!
(
format!
(
"{}"
,
parse
(
"1.2.3+build.42"
)
.unwrap
()),
~
"1.2.3+build.42"
);
assert_eq!
(
format!
(
"{}"
,
parse
(
"1.2.3-alpha1+42"
)
.unwrap
()),
~
"1.2.3-alpha1+42"
);
}
#[test]
fn
test_to_str
()
{
assert_eq!
(
parse
(
"1.2.3"
)
.unwrap
()
.to_str
(),
~
"1.2.3"
);
assert_eq!
(
parse
(
"1.2.3-alpha1"
)
.unwrap
()
.to_str
(),
~
"1.2.3-alpha1"
);
assert_eq!
(
parse
(
"1.2.3+build.42"
)
.unwrap
()
.to_str
(),
~
"1.2.3+build.42"
);
assert_eq!
(
parse
(
"1.2.3-alpha1+42"
)
.unwrap
()
.to_str
(),
~
"1.2.3-alpha1+42"
);
}
#[test]
fn
test_lt
()
{
assert
!
(
parse
(
"0.0.0"
)
<
parse
(
"1.2.3-alpha2"
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录