9 unstable releases (3 breaking)

new 0.4.4 Jun 11, 2019
0.4.3 Jun 10, 2019
0.4.2 Mar 15, 2019
0.4.1 Jan 6, 2019
0.1.0 Apr 21, 2018

#18 in Parser implementations

Download history 200/week @ 2019-02-26 464/week @ 2019-03-05 1010/week @ 2019-03-12 516/week @ 2019-03-19 917/week @ 2019-03-26 774/week @ 2019-04-02 470/week @ 2019-04-09 383/week @ 2019-04-16 405/week @ 2019-04-23 407/week @ 2019-04-30 296/week @ 2019-05-07 299/week @ 2019-05-14 268/week @ 2019-05-21 293/week @ 2019-05-28 308/week @ 2019-06-04

1,988 downloads per month
Used in 6 crates (3 directly)


5.5K SLoC


Build Status Crates.io Documentation

svgtypes is a collection of parsers, containers and writers for SVG 1.1 types.

Usage is simple as:

use svgtypes::Path;

let path: Path = "M10-20A5.5.3-4 110-.1".parse().unwrap();
assert_eq!(path.to_string(), "M 10 -20 A 5.5 0.3 -4 1 1 0 -0.1");

You can also use a low-level, pull-based parser:

use svgtypes::PathParser;

let p = PathParser::from("M10-20A5.5.3-4 110-.1");
for token in p {
    println!("{:?}", token);

You can also tweak an output format:

use svgtypes::{Path, WriteBuffer, WriteOptions};

let path_str = "M10-20A5.5.3-4 110-.1";
let path: Path = path_str.parse().unwrap();

let opt = WriteOptions {
    remove_leading_zero: true,
    use_compact_path_notation: true,
    join_arc_to_flags: true,
    .. WriteOptions::default()

assert_eq!(path.with_write_opt(&opt).to_string(), path_str);

Supported SVG types

SVG Type Rust Type Storage Parser
<color> Color Stack
<number> f64 Stack
<length> Length Stack
<angle> Angle Stack
<viewBox> ViewBox Stack
<path> Path Heap PathParser
<list-of-numbers> NumberList Heap NumberListParser
<list-of-lengths> LengthList Heap LengthListParser
<transform-list> Transform Stack TransformListParser
<list-of-points> Points Heap PointsParser
<style> - - StyleParser
<paint> - - Paint
  • All types implement from string (FromStr) and to string traits (Display, WriteBuffer).
  • The library doesn't store transform list as is. It will premultiplied.
  • style and paint types can only be parsed.


  • Complete support of paths, so data like M10-20A5.5.3-4 110-.1 will be parsed correctly.
  • Access to pull-based parsers.
  • Pretty fast.


  • Accepts only normalized values, e.g. an input text should not contain &#x20; or &data;.
  • All keywords must be lowercase. Case-insensitive parsing is supported only for colors (requires allocation for named colors).
  • The <color> followed by the <icccolor> is not supported. As the <icccolor> itself.
  • Comments inside attributes value supported only for the style attribute.
  • System colors, like fill="AppWorkspace", are not supported. They were deprecated anyway.
  • Implicit path commands are not supported. All commands will be parsed as explicit.
  • Implicit MoveTo commands will be automatically converted into explicit LineTo.


  • The library should not panic. Any panic considered as a critical bug and should be reported.
  • The library forbids unsafe code.



Migration from svgparser

This crate is a successor for the svgparser crate, but it differs from it in many ways.

  • There is no XML parser or writer. You can use any you like.
  • Unlike the svgparser this crate not only parse values but can also store and write them. Currently, it has a minimal API for manipulating this values.
  • No AttributeValue. This crate provides only value parsers. You should match attributes and values by yourself.
  • No ValueId. It's up to you how to store those values.


Rust >= 1.18


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.