Acme-Color-Rust

 view release on metacpan or  search on metacpan

lib/Acme/Color/Rust.pm  view on Meta::CPAN

package Acme::Color::Rust 0.05 {

  use warnings;
  use 5.020;
  use experimental qw( signatures );
  use FFI::Platypus 2.00;

# ABSTRACT: Color example class using Rust + FFI
# VERSION


  my $ffi = FFI::Platypus->new( api => 2, lang => 'Rust' );
  $ffi->bundle;
  $ffi->mangler(sub ($name) { "color_$name" });
  $ffi->type('object(Acme::Color::Rust,u32)' => 'color');


  $ffi->attach( new => ['string','u8','u8','u8'] => 'u32' => sub ($xsub, $class, $name, $r, $g, $bl) {
    my $index = $xsub->($name, $r, $g, $bl);
    bless \$index, $class;
  });


  $ffi->attach( name  => ['color'] => 'string' );
  $ffi->attach( red   => ['color'] => 'u8'     );
  $ffi->attach( green => ['color'] => 'u8'     );
  $ffi->attach( blue  => ['color'] => 'u8'     );

  $ffi->attach( DESTROY => ['color'] );
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Acme::Color::Rust - Color example class using Rust + FFI

=head1 VERSION

version 0.05

=head1 SYNOPSIS

 use Acme::Color::Rust;

 my $color = Acme::Color::Rust->new("red", 0xff, 0x00, 0x00);
 say "the color is ", $color->name;
 say "with red ", $color->red, " green ", $color->green, " and blue ", $color->blue;

=head1 DESCRIPTION

This class is a very simple RGB color class.  It is implemented using Rust.  It is 
mostly intended as a test for extending perl using Rust concept.

=head1 CONSTRUCTOR

=head2 new

 my $color = Acme::Color::Rust->new($name, $red, $green, $blue);

This create a new instance of L<Acme::Color::Rust>.  The name, red, green and blue 
values are passed in and the new instance is returned.  The color values should be 8
bit unsigned values (that is 0-255).

=head1 METHODS

=head2 name

 my $name = $color->name;

The name of the color.

=head2 red



( run in 1.222 second using v1.01-cache-2.11-cpan-39bf76dae61 )